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,
  })
}

/** 领取优惠券下单tel 旧 已弃用 */
export const receiveCouponApi = (params: {
  couponid: string
  coupon2phone: string
  coupon2productids: string
}) => {
  return http.get<any>('/api/nlua/call?pagevalue=98', {
    couponid: params.couponid, // 优惠券id
    coupon2phone: params.coupon2phone, // 手机号
    coupon2productids: params.coupon2productids, // 选择的商品id
  })
}

/** 领取优惠券下单tel new */
export const receiveCouponApiNew = (params: {
  // smscode: string  // 2025-05-20 16:14:54 要求去掉验证码
  couponid: string // 优惠券id
  userstype: string // 个人，企业
  usersidcardnumber: string // 身份证号
  usersshtyxydm: string // 企业统一吗
  usersname: string // 姓名
  coupon2productids: string // 产品id
  coupon2phone: string // 手机号
  filesid: string // 图片id
  coupon2merchantid: string // 商家id
}) => {
  return http.get<any>('/api/nlua/call?pagevalue=98', {
    couponid: params.couponid,
    userstype: params.userstype,
    usersidcardnumber: params.usersidcardnumber,
    usersshtyxydm: params.usersshtyxydm,
    usersname: params.usersname,
    coupon2productids: params.coupon2productids,
    coupon2phone: params.coupon2phone,
    filesid: params.filesid,
    coupon2merchantid: params.coupon2merchantid,
  })
}

/** 领取优惠劵，获取验证码 */
export const getCoupon2smsApi = (params: { coupon2phone: string }) => {
  return http.get<any>('/api/nlua/call?pagevalue=103', {
    phone: params.coupon2phone, // 手机号
  })
}

/** 获取该用户下，已领取的优惠劵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
  })
}

/** 获取已关联到当前用户的优惠券列表 */
export const getCoupon2ListApi = (params: Partial<Coupon2Type>, page: Partial<ListType>) => {
  return http.get<any>('/api/query/list?pagevalue=100', {
    ...page,
    'coupon2userid.value': params.coupon2userid, // 用户id
  })
}
