
import http from '@/http/http'
import { UploadFileParams } from '@/types/utils';
import { Idparams, ResultInterface } from '../base/BaseDataModel';
import { CustomerBillWithDetailDto, AccountPeriodDto, AccountPeriodParam, CustomerBillParam, AccountPeriodStatus, TmpReceiveParam, TmpReceiveDto, TmpReceiveStatusParam, TmpReceiveDtoAdd, TransferAccountsParams, BatchEditTmpReceive } from './accountPeriodModel';

enum Api {
    list = '/api/accountPeriod/list',
    add = '/api/accountPeriod/add',
    edit = '/api/accountPeriod/edit',
    delete = '/api/accountPeriod',
    customerBillList = '/api/customerBill/list',
    changeStatus = '/api/accountPeriod/changeStatus',
    tmpReceiveList = '/api/tmpReceive/list',
    tmpReceiveAdd = '/api/tmpReceive/add',
    tmpReceiveStatus = '/api/tmpReceive/changeStatus',
    transferred = '/api/tmpReceive/transferred',
    summaryDownload = '/api/customerBillReport/summaryDownload',
    batchEditTmpReceive = '/api/accountPeriod/batchEdit'
}

/**
 * 客户账期列表
 * @param parms 
 * @returns 
 */
export const api_accountPeriodList = async (parms: AccountPeriodParam) => {
    return await http.get<ResultInterface<AccountPeriodDto>>(Api.list, parms)
}

/**
 * 客户账期新增
 * @param parms 
 * @returns 
 */
export const api_accountPeriodAdd = async (parms: AccountPeriodDto) => {
    return await http.post(Api.add, parms)
}
/**
 * 客户账期编辑
 * @param parms 
 * @returns 
 */
export const api_accountPeriodEdit = async (parms: AccountPeriodDto) => {
    return await http.post(Api.edit, parms)
}
/**
 * 客户账期删除
 * @param parms 
 * @returns 
 */
export const api_accountPeriodDelete = async (parms: Idparams) => {
    return await http.delete(Api.delete, parms)
}
/**
 * 客户账单列表
 * @param parms 
 * @returns 
 */
export const api_customerBillList = async (parms: CustomerBillParam) => {
    return await http.post<ResultInterface<CustomerBillWithDetailDto>>(Api.customerBillList, parms)
}

/**
 * 客户账期是否启用/停用
 * @param parms 
 * @returns 
 */
export const api_accountPeriodChangeStatus = async (parms: AccountPeriodStatus) => {
    return await http.post(Api.changeStatus, parms)
}

/**
 * 临时收货列表
 */
export const api_tmpReceiveList = async (parms: TmpReceiveParam) => {
    return await http.get<ResultInterface<TmpReceiveDto>>(Api.tmpReceiveList, parms)
}


/**
 * 临时收货是否启用/停用
 * @param parms 
 * @returns 
 */
export const api_tmpReceiveChangeStatus = async (parms: TmpReceiveStatusParam) => {
    return await http.post(Api.tmpReceiveStatus, parms)
}

/**
 * 转账接口
 * @param parms 
 * @returns 
 */
export const api_transferred = async (parms: TransferAccountsParams) => {
    return await http.post(Api.transferred, parms)
}

/**
 * 临时收货新增
 * @param parms
 * @returns
 */
export const api_tmpReceiveAdd = async (
    parms: TmpReceiveDtoAdd,
    uploadFileList: File[]
) => {
    const data: UploadFileParams = {
        filename: "files",
        files: uploadFileList,
        data: {
            ...parms,
        },
    };
    return await http.uploadFile(Api.tmpReceiveAdd, data);
};

/**
 * 客户账单报表下载
 */
export const api_customerBillReportDownload = async (parms: CustomerBillParam) => {
    return await http.download(Api.summaryDownload, parms)
}

/**
 * 批量修改账期额度
 * @param parms 
 * @returns 
 */
export const api_batchEditTmpReceive = async (parms: BatchEditTmpReceive) => {
    return await http.post(Api.batchEditTmpReceive, parms)
}
