import { http } from '@/utils/http'
import type { Coupon1Type } from '@/types/coupon1'
import type { Coupon2Type } from '@/types/coupon2'
import type { ListType, ListResponseType } from '@/types/list'
// import { parseQueryValues } from '@/utils'

/** 获取商品可用优惠券列表 */
export const getCouponListApi = (params: Partial<Coupon1Type>, page: Partial<ListType>) => {
  return http.get<ListResponseType<Coupon1Type>>('/api/query/list?pagevalue=33', {
    ...page,
    // ...parseQueryValues(params),
    'couponproductids.like': params.couponproductids,
  })
}

/** 领取优惠券 */
export const receiveCouponApi = (couponid: string) => {
  return http.get<any>('/api/nlua/call?pagevalue=43', {
    couponid,
  })
}

/** 获取该用户下，已领取的优惠劵id，用于判断是否可以领取 */
export const getCoupon2idApi = (
  params: Partial<Coupon2Type> & {
    coupon2userid: string
    coupon2isused: number
    coupon2productids: string
  },
) => {
  return http.get<any>('/api/query/list?pagevalue=38', {
    'coupon2userid.value': params.coupon2userid, // 用户id
    'coupon2isused.value': params.coupon2isused, // 0:未使用 1:已使用
    'coupon2productids.like': params.coupon2productids, // 产品id
  })
}
