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

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

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

interface Coupon2PartialEntity
  extends Partial<Omit<Coupon2Entity, 'coupon2code'>> {
  coupon2code?: string;
}

interface Coupon2QueryParams extends Coupon2PartialEntity, PageConfig {}

/**
 * 我的优惠券信息_列表
 */
export async function getCoupon2ListApi(params: Coupon2QueryParams) {
  return requestClient.post<any>('/api/query/list?pagevalue=38', {
    ...params,
  });
}

/**
 * 我的优惠券信息_详情
 */
export async function getCoupon2DetailApi(data: { coupon2sid: string }) {
  return requestClient.post<any>(
    '/api/query/view?pagevalue=39',
    {
      ...parseQueryValues(data),
    },
    { formatData: true }, // 格式化返回数据
  );
}

/**
 * 我的优惠券信息_新增
 */
export async function addCoupon2Api(data: Coupon2Entity) {
  return requestClient.post<any>('/api/add?pagevalue=40', { ...data });
}

/**
 * 我的优惠券信息_编辑
 */
export async function editCoupon2Api(data: Coupon2Entity) {
  return requestClient.post<any>('/api/up?pagevalue=41', { ...data });
}
