import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** ERP 售后登记信息 */
export interface AfterSaleRegister {
          id: number; // 售后登记编号
          orderId?: number; // 关联销售订单编号
          orderItemId?: number; // 关联销售订单项编号
          afterSaleType?: number; // 售后类型：1-退货，2-换货，3-维修，4-退款
          applyReason?: string; // 申请原因
          contactName?: string; // 联系人
          contactPhone?: string; // 联系电话
          applyStatus?: number; // 申请状态：1-待审核，2-审核通过，3-审核驳回，4-已取消
          rejectReason: string; // 驳回原因（审核驳回时填写）
          applicant?: string; // 申请人
          auditUser: string; // 审核人
          auditTime: string | Dayjs; // 审核时间
  }

// ERP 售后登记 API
export const AfterSaleRegisterApi = {
  // 查询ERP 售后登记分页
  getAfterSaleRegisterPage: async (params: any) => {
    return await request.get({ url: `/erp/after-sale-register/page`, params })
  },

  // 查询ERP 售后登记详情
  getAfterSaleRegister: async (id: number) => {
    return await request.get({ url: `/erp/after-sale-register/get?id=` + id })
  },

  // 新增ERP 售后登记
  createAfterSaleRegister: async (data: AfterSaleRegister) => {
    return await request.post({ url: `/erp/after-sale-register/create`, data })
  },

  // 修改ERP 售后登记
  updateAfterSaleRegister: async (data: AfterSaleRegister) => {
    return await request.put({ url: `/erp/after-sale-register/update`, data })
  },

  // 删除ERP 售后登记
  deleteAfterSaleRegister: async (id: number) => {
    return await request.delete({ url: `/erp/after-sale-register/delete?id=` + id })
  },

  /** 批量删除ERP 售后登记 */
  deleteAfterSaleRegisterList: async (ids: number[]) => {
    return await request.delete({ url: `/erp/after-sale-register/delete-list?ids=${ids.join(',')}` })
  },

  // 导出ERP 售后登记 Excel
  exportAfterSaleRegister: async (params) => {
    return await request.download({ url: `/erp/after-sale-register/export-excel`, params })
  }
}