import baseAxios from '../index'
import { eProductType, eProductStatus, eGuaranteeType, editableProductStatus } from "@/types/loanProduct"
import { iLoanProdcutItem } from "./type"
const prefix = '/loan/admin'

export default class LoanProductService {
  static instance: LoanProductService
  static getInstance() {
    if (!LoanProductService.instance) {
      LoanProductService.instance = new LoanProductService()
    }
    return LoanProductService.instance
  }

  addLoan(
    data: {
      apply_cond: string
      apply_to: string
      features: string
      guarantee_type: eGuaranteeType
      inst_name: string
      loan_type: eProductType
      max_amount: number
      max_date: number
      product_name: string
      products: string
      rate_lower: number
      rate_upper: number
      submit_cond: string
      min_date: number
      min_amount: number
    }
  ) {
    return baseAxios({
      url: prefix + '/add',
      method: 'POST',
      data,
    })
  }

  modifyLoan(
    data: {
      apply_cond: string
      apply_to: string
      features: string
      guarantee_type: eGuaranteeType
      inst_name: string
      loan_type: eProductType
      max_amount: number
      max_date: number
      product_name: string
      products: string
      rate_lower: number
      rate_upper: number
      submit_cond: string
      min_amount: number
      min_date: number
      uuid:string
    }
  ) {
    return baseAxios({
      url: prefix + '/modify',
      method: 'POST',
      data,
    })
  }

  modifyLoanStatus(data: {
    product_status: editableProductStatus,
    uuid: string
  }) {
    return baseAxios({
      url: prefix + '/modify/status',
      method: 'POST',
      data,
    })
  }

  queryDirectLoanReq(data: {
    product_name?:string,
    end_time?: number
    limit?: number
    loan_type: eProductType
    offset?: number
    product_status: eProductStatus
    start_time?: number
  }) {
    return baseAxios<{
      count: number
      items: iLoanProdcutItem[]
      total: number
    }>({
      url: '/loan/query/direct/list',
      method: 'POST',
      data,
    })
  }


  queryInfo(uuid: string) {
    return baseAxios({
      url: '/loan/query/info?uuid=' + uuid,
      method: 'get',
    })
  }

  deleteLoanItem(uuid: string) {
    return baseAxios({
      url: prefix + '/delete?uuid=' + uuid,
      method: 'delete',
    })
  }

}