import { request } from "@/http/axios"
import { GetBalanceResponse, GetOrdersByOpenIdDTO, QyLoginDTO, QyLoginRequestParams, ShopGoodsResponseData, SubmitOrderRequestData, SubmitOrderResponseData } from './type'
import { GetOpenIdRequestParams } from './type'



/** 获取当前登录用户详情 */
export function getShopGoodsApi() {
  return request<ShopGoodsResponseData>({
    url: "shop/goods",
    method: "get"
  })
}

/** 提交订单接口 */
export function submitOrderApi(data: SubmitOrderRequestData) {
  return request<SubmitOrderResponseData>({
    url: "order/submit",
    method: "post",
    data
  })
}

/** 获取微信openid */
export function getOpenIdApi(params: GetOpenIdRequestParams) {
  return request<ApiResponseData<string>>({
    url: "payment/getOpenId",
    method: "get",
    params  
  })
}
/** 企业微信登录 */
export function qyLogin(params: QyLoginRequestParams) {
  return request<ApiResponseData<QyLoginDTO>>({
    url: "payment/login/qy",
    method: "get",
    params  
  })
}

/** 根据openid获取用户订单信息 */
export function getOrdersByOpenIdApi(openid: string) {
  return request<ApiResponseData<GetOrdersByOpenIdDTO>>({
    url: `order/user/${openid}`,
    method: "get"
  })
}

/** 打开储物柜接口 */
export function openCabinetApi(orderId: number, orderGoodsId: number) {
  return request<ApiResponseData<void>>({
    url: `order/openCabinet/${orderId}/${orderGoodsId}`,
    method: "post"
  })
}

/** 获取用户余额接口 */
export function getBalanceApi(openid: string) {
  return request<ApiResponseData<GetBalanceResponse>>({
    url: "payment/getBalance",
    method: "get",
    params: { openid }
  })
}
export function getBalanceByQyUserid(corpid: string, userid: string) {
  return request<ApiResponseData<GetBalanceResponse>>({
    url: "payment/getBalanceByQyUserid",
    method: "get",
    params: { corpid, userid  }
  })
}
