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



/** 获取商品列表 */
export function getShopGoodsListApi(corpid: string, belongType: number) {
  return request<ApiResponseData<SearchGoodsDO[]>>({
    url: "shop/goods/list",
    method: "get",
    params: { corpid, belongType }
  });
}

export function getShopGoodsApi(shopId: number|null) {
  return request<ShopGoodsResponseData>({
    url: "shop/goods",
    method: "get",
    params: {
      shopId: shopId ? shopId : undefined
    }
  })
}

/** 提交订单接口 */
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  
  })
}
export function fakeQyLoginApi(params: {corpid: string, userid: string}) {
  return request<ApiResponseData<QyLoginDTO>>({
    url: "payment/login/qy/fake",
    method: "get",
    params  
  })
}

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

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

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

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

export interface GetShopListParams {
  corpid: string;
  mode?: number;
  eqMode?: number;
}

export function getShopListApi(params: GetShopListParams) {
  return request<ApiResponseData<ShopEntity[]>>({
    url: "shop/list",
    method: "get",
    params
  })
}

/** 获取模式列表 */
export function getModeListApi() {
  return request<ApiResponseData<number[]>>({
    url: "shop/mode/list",
    method: "get"
  })
}