import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {
    AllBusinessVO,
    AllBusinessForm,
    AllBusinessQuery,
    BusinessTransferDTO, AddConcateDTO, LostBusinessDTO
} from '@/api/business/allBusiness/types';

/**
 * 查询商机列表
 * @param query
 * @returns {*}
 */

export const listAllBusiness = (query?: AllBusinessQuery & PageQuery): AxiosPromise<{ records: AllBusinessVO[] }> => {
    return request({
        url: '/business/list',
        method: 'post',
        data: query
    });
};

/**
 * 查询商机详细
 * @param id
 */
export const getById = (param : {id?: string|number, scopMenuId?: string}): AxiosPromise<AllBusinessVO> => {
    return request({
        url: '/business/get-pre-nex-by-id',
        method: 'post',
        data: param
    });
};

export const getPreNexById = (param : {id?: string|number, scopMenuId?: string}): AxiosPromise<AllBusinessVO> => {
    return request({
        url: '/business/get-pre-nex-by-id',
        method: 'post',
        data: param
    });
};

/**
 * 新增商机
 * @param data
 */
export const addAllBusiness = (data: AllBusinessForm) => {
    return request({
        url: '/business/add',
        method: 'post',
        data: data
    });
};
/**
 * 新增商机
 * @param data
 */
export const changeStage = (data: AllBusinessForm) => {
    return request({
        url: '/business/change-stage',
        method: 'post',
        data: data
    });
};

/**
 * 修改商机
 * @param data
 */
export const updateAllBusiness = (data: AllBusinessForm) => {
    return request({
        url: '/business/allBusiness',
        method: 'put',
        data: data
    });
};

/**
 * 删除商机
 * @param id
 */
export const delAllBusiness = (id: string | number | Array<string | number>) => {
    return request({
        url: '/business/delete',
        method: 'post',
        data: {id: id}
    });
};
/**
 * 转移商机
 * @param id
 */
export const transferBusiness = (businessTransferDTO : BusinessTransferDTO) => {
    return request({
        url: '/business/transfer',
        method: 'post',
        data: businessTransferDTO
    });
};

/**
 * 添加联系人
 * @param id
 */
export const updateConcat = (addConcateDTO : AddConcateDTO) => {
    return request({
        url: '/business/updateConcat',
        method: 'post',
        data: addConcateDTO
    });
};

/**
 * 更改状态
 * @param id
 */
export const lostBusiness = (lostBusinessDTO : LostBusinessDTO) => {
    return request({
        url: '/business/change-loss',
        method: 'post',
        data: lostBusinessDTO
    });
};
