import request from '@/config/axios'

// ERP 银行流水 VO
export interface BankTransactionVO {
  id: number // 流水编号
  transactionNo: string // 交易流水号
  accountId: number // 结算账户编号
  accountName?: string // 结算账户名称
  accountNo: string // 账户号
  transactionInstitution: string // 交易机构
  transactionAmount: number // 交易金额
  transactionType: number // 交易类型：1-收入 2-支出
  counterpartyAccount: string // 交易对手账户
  counterpartyName: string // 交易对手户名
  counterpartyBank: string // 交易对手银行
  operatorTeller: string // 操作柜员
  summary: string // 摘要
  remark: string // 备注信息
  transactionTime: Date // 交易时间
  createTime: Date // 创建时间
}

// ERP 银行流水 API
export const BankTransactionApi = {
  // 查询银行流水分页
  getBankTransactionPage: async (params: any) => {
    return await request.get({ url: `/erp/bank-transaction/page`, params })
  },

  // 查询银行流水详情
  getBankTransaction: async (id: number) => {
    return await request.get({ url: `/erp/bank-transaction/get?id=` + id })
  },

  // 新增银行流水
  createBankTransaction: async (data: BankTransactionVO) => {
    return await request.post({ url: `/erp/bank-transaction/create`, data })
  },

  // 修改银行流水
  updateBankTransaction: async (data: BankTransactionVO) => {
    return await request.put({ url: `/erp/bank-transaction/update`, data })
  },

  // 删除银行流水
  deleteBankTransaction: async (id: number) => {
    return await request.delete({ url: `/erp/bank-transaction/delete?id=` + id })
  },

  // 导出银行流水 Excel
  exportBankTransaction: async (params: any) => {
    return await request.download({ url: `/erp/bank-transaction/export-excel`, params })
  },

  // 获取导入模板
  getImportTemplate: async () => {
    return await request.download({ url: `/erp/bank-transaction/get-import-template` })
  },

  // 导入银行流水
  importBankTransaction: async (file: File, updateSupport: boolean) => {
    const formData = new FormData()
    formData.append('file', file)
    return await request.post({
      url: `/erp/bank-transaction/import?updateSupport=${updateSupport}`,
      data: formData,
      headersType: 'multipart/form-data'
    })
  }
}
