syntax = "v1"

info (
	title:   "产品查询服务"
	desc:    "产品查询服务"
	author:  "Liangzai"
	email:   "2440983361@qq.com"
	version: "v1"
)

//============================> query v1 <============================
// 查询基本类型定义
type Query {
	Id          int64                  `json:"id"`           // 主键ID
	OrderId     int64                  `json:"order_id"`     // 订单ID
	OrderNo     string                 `json:"order_no"`     // 订单号
	UserId      int64                  `json:"user_id"`      // 用户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"` // 查询状态
	IsPaid      bool                   `json:"is_paid"`     // 是否支付
	IsQueryCompleted bool              `json:"is_query_completed"` // 查询是否完成
	IsAuthCompleted bool               `json:"is_auth_completed"`  // 授权是否完成
	IsRefunded bool               `json:"is_refunded"`  // 是否退款
}


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: UserAuthInterceptor
)
service main {
	@doc "query service"
	@handler queryService
	post /query/service/:product (QueryServiceReq) returns (QueryServiceResp)
}

@server (
	prefix: api/v1
	group:  query
	jwt:    JwtAuth
	middleware: UserAuthInterceptor
)
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 (QueryDetailByOrderIdResp)

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

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

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

	@doc "确认查询状态"
	@handler confirmQueryState
	post /query/confirm_state (ConfirmQueryStateReq) returns (ConfirmQueryStateResp)

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

	@doc "补查"
	@handler queryRecheck
	post /query/recheck/:query_id (QueryRecheckReq) returns (QueryRecheckResp)
}

type (
	QueryGenerateShareLinkReq {
		OrderId *int64 `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"`
	}
	QueryExampleResp {
		Query
	}
)

type (
	QueryDetailReq {
		Id int64 `path:"id"`
	}
	QueryDetailResp {
		Query
	}
)

type (
	QueryDetailByOrderIdReq {
		OrderId int64 `path:"order_id"`
	}
	QueryDetailByOrderIdResp {
		Query
	}
)

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

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


type (
	UpdateQueryDataReq {
		Id        int64  `json:"id"`         // 查询ID
		QueryData string `json:"query_data"` // 查询数据(未加密的JSON)
	}
	UpdateQueryDataResp {
		Id        int64  `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 (QueryShareDetailResp)

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

}
type (
	QueryShareDetailReq {
		Id string `path:"id"`
	}
	QueryShareDetailResp {
		Status string `json:"status"`
		Query
	}
)
type QuerySingleTestReq {
	Params map[string]interface{} `json:"params"`
	Api    string                 `json:"api"`
}

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

// 新增接口的请求、响应类型定义
type (
	ConfirmQueryStateReq {
		OrderID int64 `json:"order_id" validate:"required"`
	}
	ConfirmQueryStateResp {
		OrderState     string `json:"order_state"`      // 查询状态，例如"pending"、"success"、"failed"等
		QueryState string `json:"query_state"`
	}
)

type (
	QueryRecheckReq {
		QueryId int64 `path:"query_id"`
	}
	QueryRecheckResp {
		Success bool `json:"success"`
	}
)