import type { Coupon1Entity, PageConfig } from '@vben/types';

import { parseQueryValues } from '@vben/utils';

import { requestClient } from '#/api/request';

interface Coupon1PartialEntity
  extends Partial<Omit<Coupon1Entity, 'couponmc'>> {
  couponmc?: string;
}

interface Coupon1QueryParams extends Coupon1PartialEntity, PageConfig {}

/**
 * 优惠劵主券_列表
 */
export async function getCoupon1ListApi(params: Coupon1QueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=33', {
    ...params,
    'couponproductids.like': params.couponproductids || '',
  });
}

/**
 * 优惠劵主券_详情
 */
export async function getCoupon1DetailApi(data: { couponid: string }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=34',
    {
      ...parseQueryValues(data),
    },
    { formatData: true }, // 格式化返回数据
  );
}

/**
 * 优惠劵主券_新增
 */
export async function addCoupon1Api(data: Coupon1Entity) {
  return requestClient.post<any>('/api/add?pagevalue=35', { ...data });
}

/**
 * 优惠劵主券_编辑
 */
export async function editCoupon1Api(data: Coupon1Entity) {
  return requestClient.post<any>('/api/up?pagevalue=36', { ...data });
}

/**
 * 优惠劵主券_删除
 */
export async function deleteCoupon1Api(data: { 'couponid.value': string }) {
  return requestClient.post<any>('/api/del?pagevalue=37', { ...data });
}

/**
 * 优惠劵领劵
 */
export async function receiveCouponApi(data: { couponid: string }) {
  return requestClient.post<any>('/api/nlua/call?pagevalue=115', {
    ...data,
  });
}

/**
 * 优惠劵下单
 */
export async function useCouponApi(data: {
  filesid: string; // 发票id
  orderscouponid: string; // 优惠码
  ordersphone: string; // 手机号
  ordersproductid: string; // 产品id
  ordersproductsn: string; // SN号
  ordersuserid1: string; // 销售网点id
}) {
  return requestClient.post<any>('/api/nlua/call?pagevalue=116', {
    ...data,
  });
}
