syntax = "v1"

info (
	title:   "产品查询服务"
	desc:    "产品查询服务"
	version: "v1"
)

//============================> query v1 <============================
// 查询基本类型定义
type Query {
	Id          string                 `json:"id"` // 主键ID
	OrderId     string                 `json:"order_id"` // 订单ID
	UserId      string                 `json:"user_id"` // 用户ID
	Product     string                 `json:"product"` // 产品ID
	ProductName string                 `json:"product_name"` // 产品ID
	QueryParams map[string]interface{} `json:"query_params"`
	QueryData   []QueryItem            `json:"query_data"`
	CreateTime  string                 `json:"create_time"` // 创建时间
	UpdateTime  string                 `json:"update_time"` // 更新时间
	QueryState  string                 `json:"query_state"` // 查询状态
}

type QueryItem {
	Feature interface{} `json:"feature"`
	Data    interface{} `json:"data"` // 这里可以是 map 或 具体的 struct
}

@server (
	prefix:     api/v1
	group:      query
	middleware: AuthInterceptor
)
service main {
	@doc "query service agent"
	@handler queryServiceAgent
	post /query/service_agent/:product (QueryServiceReq) returns (QueryServiceResp)

	@handler queryServiceApp
	post /query/service_app/:product (QueryServiceReq) returns (QueryServiceResp)
}

type (
	QueryReq {
		Data string `json:"data" validate:"required"`
	}
	QueryResp {
		Id string `json:"id"`
	}
)

type (
	QueryServiceReq {
		Product         string `path:"product"`
		Data            string `json:"data" validate:"required"`
		AgentIdentifier string `json:"agent_identifier,optional"`
		App             bool   `json:"app,optional"`
	}
	QueryServiceResp {
		Id           string `json:"id"`
		AccessToken  string `json:"accessToken"`
		AccessExpire int64  `json:"accessExpire"`
		RefreshAfter int64  `json:"refreshAfter"`
	}
)

@server (
	prefix:     api/v1
	group:      query
	jwt:        JwtAuth
	middleware: AuthInterceptor
)
service main {
	@doc "query service"
	@handler queryService
	post /query/service/:product (QueryServiceReq) returns (QueryServiceResp)
}

@server (
	prefix:     api/v1
	group:      query
	jwt:        JwtAuth
	middleware: AuthInterceptor
)
service main {
	@doc "获取查询临时订单"
	@handler queryProvisionalOrder
	get /query/provisional_order/:id (QueryProvisionalOrderReq) returns (QueryProvisionalOrderResp)

	@doc "查询列表"
	@handler queryList
	get /query/list (QueryListReq) returns (QueryListResp)

	@doc "查询详情 按订单号 付款查询时"
	@handler queryDetailByOrderId
	get /query/orderId/:order_id (QueryDetailByOrderIdReq) returns (string)

	@doc "查询详情 按订单号"
	@handler queryDetailByOrderNo
	get /query/orderNo/:order_no (QueryDetailByOrderNoReq) returns (string)

	@doc "重试查询"
	@handler queryRetry
	post /query/retry/:id (QueryRetryReq) returns (QueryRetryResp)

	@doc "更新查询数据"
	@handler updateQueryData
	post /query/update_data (UpdateQueryDataReq) returns (UpdateQueryDataResp)

	@doc "生成分享链接"
	@handler QueryGenerateShareLink
	post /query/generate_share_link (QueryGenerateShareLinkReq) returns (QueryGenerateShareLinkResp)
}

type (
	QueryGenerateShareLinkReq {
		OrderId *string `json:"order_id,optional"`
		OrderNo *string `json:"order_no,optional"`
	}
	QueryGenerateShareLinkResp {
		ShareLink string `json:"share_link"`
	}
)

// 获取查询临时订单
type (
	QueryProvisionalOrderReq {
		Id string `path:"id"`
	}
	QueryProvisionalOrderResp {
		Name    string  `json:"name"`
		IdCard  string  `json:"id_card"`
		Mobile  string  `json:"mobile"`
		Product Product `json:"product"`
	}
)

type (
	QueryListReq {
		Page     int64 `form:"page"` // 页码
		PageSize int64 `form:"page_size"` // 每页数据量
	}
	QueryListResp {
		Total int64   `json:"total"` // 总记录数
		List  []Query `json:"list"` // 查询列表
	}
)

type (
	QueryExampleReq {
		Feature string `form:"feature"`
	}
)

type (
	QueryDetailByOrderIdReq {
		OrderId string `path:"order_id"`
	}
)

type (
	QueryDetailByOrderNoReq {
		OrderNo string `path:"order_no"`
	}
)

type (
	QueryRetryReq {
		Id string `path:"id"`
	}
	QueryRetryResp {
		Query
	}
)

type (
	UpdateQueryDataReq {
		Id        string `json:"id"` // 查询ID
		QueryData string `json:"query_data"` // 查询数据(未加密的JSON)
	}
	UpdateQueryDataResp {
		Id        string `json:"id"`
		UpdatedAt string `json:"updated_at"` // 更新时间
	}
)

@server (
	prefix: api/v1
	group:  query
)
service main {
	@handler querySingleTest
	post /query/single/test (QuerySingleTestReq) returns (QuerySingleTestResp)

	@doc "查询详情"
	@handler queryShareDetail
	get /query/share/:id (QueryShareDetailReq) returns (string)

	@doc "查询示例"
	@handler queryExample
	get /query/example (QueryExampleReq) returns (string)
}

type (
	QueryShareDetailReq {
		Id string `path:"id"`
	}
)

type QuerySingleTestReq {
	Params map[string]interface{} `json:"params"`
	Api    string                 `json:"api"`
}

type QuerySingleTestResp {
	Data interface{} `json:"data"`
	Api  string      `json:"api"`
}

