import request from '/@/utils/request';
import type { ClientSetting, ClientSettingParams, ClientSettingGetParams, ClientSettingTypeEnum } from './types';
import { AxiosPromise } from 'axios';

/**
 * 新增客户设置
 * @param params 
 * @returns 
 */
export function clientSettingAddApi(data: ClientSettingParams) {
    return request({
        url: '/client/setting/info/add',
        method: 'post',
        data
    })
}


/**
 * 批量新增客户自定义设置
 * @param data 
 * @returns 
 */
export function clientSettingAddBatchApi(data: ClientSettingParams[]) {
    return request({
        url: '/client/setting/info/addList',
        method: 'post',
        data
    })
}

/**
 * 删除指定客户自定义设置
 * @param id 
 * @returns 
 */
export function clientSettingDelApi(id: number) {
    return request({
        url: '/client/setting/info/delete',
        method: 'post',
        data: { id }
    })
}


/**
 * 批量删除客户自定义设置
 * @param ids 
 * @returns 
 */
export function clientSettingDelBatchApi(ids: string) {
    return request({
        url: '/client/setting/info/deleteAll',
        method: 'post',
        data: { ids }
    })
}


/**
 * 根据id获取客户自定义设置详情
 * @param id 
 * @returns 
 */
export function clientSettingDetailByIdApi(id: number): AxiosPromise<ClientSetting | null> {
    return request({
        url: '/client/setting/info/detail',
        method: 'post',
        data: { id }
    })
}

/**
 * 根据code获取自定义设置详情
 * @param code 
 * @returns 
 */
export function clientSettingDetailByCodeApi(code: string): AxiosPromise<ClientSetting | null> {
    return request({
        url: '/client/setting/info/detail2',
        method: 'post',
        data: { code }
    })
}

/**
 * 根据type获取自定义设置详情
 * @param params 
 * @returns 
 */
export function clientSettingDetailBySettingTypeApi(params: { clientCode: string; type: ClientSettingTypeEnum }): AxiosPromise<ClientSetting | null> {
    return request({
        url: '/client/setting/info/getAdvanceDeliveryByType',
        method: 'post',
        params
    })
}

/**
 * 获取客户自定义配置列表
 * @param data 
 * @returns 
 */
export function clientSettingListApi(params: ClientSettingGetParams): AxiosPromise<{ list: ClientSetting[]; total: number; [key: string]: any; }>  {
    return request({
        url: '/client/setting/info/list',
        method: 'post',
        params
    })
}


/**
 * 更新客户自定义配置项
 * @param data 
 * @returns 
 */
export function clientSettingUpdateApi(data: ClientSettingParams) {
    return request({
        url: '/client/setting/info/update',
        method: 'post',
        data
    })
}