import { get, post, type ApiResponse } from '../utils/request'

export type GoodsItem = {
  checked: boolean
  goods_id: string
  goods_name: string
  origin_price: string
  pay_type: string
  price: string
  sign_value: string
  weixinMpOriId: string
  recommend?: boolean
}

export type OrderPayload = Record<string, unknown> & {
  goods_id: string
  pay_type: string
  source: string
  pay_source: string
  extra: Record<string, unknown>
}

export type OrderResult = {
  appId?: string
  h5_url?: string
  orderId?: string
  outTradeNo?: string
  payFee?: string
  payParam?: string
  payType?: string
  unifyOrderId?: string
}

export type OrderStatus = {
  status?: string
  [key: string]: unknown
}

// goods
export function getGoods() {
  return get<ApiResponse<GoodsItem[]>>('/api/order/goods', undefined, { tokenType: 'permanent' })
}

// order
export function order(payload: OrderPayload) {
  return post<ApiResponse<OrderResult>>('/api/order', payload, { tokenType: 'permanent' })
}

export function checkOrder(orderId: string) {
  return get<ApiResponse<OrderStatus>>('/api/order', { order_id: orderId }, { tokenType: 'permanent' })
}
