import { http } from '@/utils/http';

export interface SearchReturnApprovalQuery extends BasePageQuery {
  approvalId?: number;
  orderId?: number;
  goodsId?: number;
  status?: number;
  approvalTime?: string;
  /** 
 * 支付方式
 * @remarks 
 * wechat-微信支付 | balance-借呗支付
 */
  paymentMethod?: string;
  /**
   * 审批类型
   * @remarks
   * 0为借还柜 1为固资通
   */
  approvalType: number;
  /**
   * 处理状态
   * @remarks
   * 0:待处理 1:已处理
   */
  handleStatus?: number;
  /**
   * 搜索字符串
   * @remarks
   * 搜索商品名称、申请人
   */
  searchStr?: string;
}

/** 退货审批DTO */
/** 退货审批DTO */
export interface ReturnApprovalDTO {
  /** 审批编号 */
  approvalId?: number;
  /** 关联订单ID */
  orderId: number;
  /** 关联商品ID */
  goodsId: number;
  /** 归还数量 */
  returnQuantity: number;
  /** 商品单价 */
  goodsPrice: number;
  /** 退还金额 */
  returnAmount: number;
  /** 归还图片路径（逗号分隔） */
  returnImages: string;
  /** 审核图片路径（逗号分隔） */
  auditImages: string;
  /** 归还说明 */
  returnRemark?: string;
  /** 审核说明 */
  auditRemark?: string;
  /** 审批状态(1待审核 2已通过 3已驳回) */
  status: number;
  statusStr: string;
  creatorId?: number;
  createTime?: Date;
  updaterId?: number;
  updateTime?: Date;
  approvalTime?: Date;
  goodsName?: string;
  coverImg?: string;
  mobile?: string;
  name?: string;
  /**
 * 支付方式
 * @remarks 
 * wechat-微信支付 | balance-借呗支付
 */
  paymentMethod?: string;
}

export interface AddReturnApprovalCommand {
  /** 关联订单ID */
  orderId: number;
  /** 关联商品ID */
  goodsId: number;
  /** 归还数量 */
  returnQuantity: number;
  /** 归还图片路径（逗号分隔） */
  returnImages: string;
  /** 归还说明 */
  returnRemark?: string;
}

export interface UpdateReturnApprovalCommand {
  /** 审批编号 */
  approvalId: number;
  /** 归还数量 */
  returnQuantity: number;
  /** 审核图片路径（逗号分隔） */
  auditImages: string;
  /** 审核说明 */
  auditRemark?: string;
  /** 审批状态(1待审核 2已通过 3已驳回) */
  status: number;
}

/** 获取退货审批列表 */
export const getReturnApprovalListApi = (params?: SearchReturnApprovalQuery) => {
  return http.request<ResponseData<PageDTO<ReturnApprovalDTO>>>(
    'get',
    '/shop/returnApproval', {
    params: {
      ...params,
      approvalTime: params?.approvalTime ? params.approvalTime : undefined
    }
  }
  );
};
/** 批量导出订单 */
export const exportReturnApprovalExcelApi = (params: SearchReturnApprovalQuery, fileName: string) => {
  return http.download("/shop/returnApproval/excel", fileName, {
    params: {
      ...params,
      approvalTime: params?.approvalTime ? params.approvalTime : undefined
    }
  });
};

/** 新增退货审批 */
export const addReturnApprovalApi = (data: AddReturnApprovalCommand) => {
  return http.request<ResponseData<void>>('post', '/shop/returnApproval', {
    data
  });
};

/** 修改退货审批 */
export const updateReturnApprovalApi = (
  approvalId: number,
  data: UpdateReturnApprovalCommand
) => {
  return http.request<ResponseData<void>>(
    'put',
    `/shop/returnApproval/${approvalId}`,
    { data }
  );
};

/** 批量删除退货审批 */
export const deleteReturnApprovalApi = (approvalIds: (number | string)[]) => {
  return http.request<ResponseData<void>>(
    'delete',
    `/shop/returnApproval/${approvalIds.join(',')}`
  );
};