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

/** 应收单信息 */
export interface ReceivableOrder {
          id: number; // 应收单ID（主键）
          aroCode?: string; // 应收单号（唯一，如AR20260115001）
          customerId?: number; // 客户ID（外键关联customer表）
          billDate?: string | Dayjs; // 单据日期
          dueDate?: string | Dayjs; // 到期收款日期
          totalAmount?: number; // 应收总金额
          taxAmount?: number; // 税额
          nonTaxAmount?: number; // 不含税金额
          subjectId: number; // 会计科目ID（外键关联科目表，对应应收账款科目）
          billType?: number; // 单据类型：1-销售发票，2-服务费账单，3-其他应收
          status?: number; // 状态：0-草稿，1-待审核，2-已审核，3-已核销，4-已取消
          remark: string; // 备注
          auditUser: string; // 审核人
          auditTime: string | Dayjs; // 审核时间
  }

// 应收单 API
export const ReceivableOrderApi = {
  // 应收单自动更新
  autoUpdateReceivableOrder: async () => {
    return await request.post({ url: `/erp/receivable-order/autoUpdate` })
  },
  // 应收单自动获取展示
  autoGetShowReceivableOrder: async (params?: any) => {
    return await request.get({ url: `/erp/receivable-order/autoGetShow`, params })
  },
  // 查询应收单分页
  getReceivableOrderPage: async (params: any) => {
    return await request.get({ url: `/erp/receivable-order/page`, params })
  },

  // 查询应收单详情
  getReceivableOrder: async (id: number) => {
    return await request.get({ url: `/erp/receivable-order/get?id=` + id })
  },

  // 新增应收单
  createReceivableOrder: async (data: ReceivableOrder) => {
    return await request.post({ url: `/erp/receivable-order/create`, data })
  },

  // 修改应收单
  updateReceivableOrder: async (data: ReceivableOrder) => {
    return await request.put({ url: `/erp/receivable-order/update`, data })
  },

  // 删除应收单
  deleteReceivableOrder: async (id: number) => {
    return await request.delete({ url: `/erp/receivable-order/delete?id=` + id })
  },

  /** 批量删除应收单 */
  deleteReceivableOrderList: async (ids: number[]) => {
    return await request.delete({ url: `/erp/receivable-order/delete-list?ids=${ids.join(',')}` })
  },

  // 导出应收单 Excel
  exportReceivableOrder: async (params) => {
    return await request.download({ url: `/erp/receivable-order/export-excel`, params })
  },
}
