import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { UserVO, UserForm, UserQuery, ResetPwdForm } from '@/api/system/user/types';
import { AllBusinessVO } from "@/api/business/allBusiness/types";

/**
 * 查询用户列表
 * @param query
 * @returns {*}
 */

export const listUser = (query?: UserQuery): AxiosPromise<{ records: UserVO[] }> => {
    return request({
        url: '/sys/user/pagelist',
        method: 'post',
        data: query
    });
};
/**
 * 查询未绑定的用户
 * @param query
 * @returns {*}
 */

export const unallocatedUserList = (query?: UserQuery): AxiosPromise<UserVO[]> => {
    return request({
        url: '/sys/user/pagelistunbindRole',
        method: 'post',
        data: query
    });
};

/**
 * 启用禁用员工
 * @param query
 * @returns {*}
 */

export const enableUser = (ids: Array<string | number>, enable: string | number | boolean): AxiosPromise<UserVO[]> => {
    return request({
        url: '/sys/user/enable',
        method: 'post',
        data: { ids: ids, enable: enable }
    });
};

/**
 * 查询用户详细
 * @param id
 */
export const getUser = (id: string | number): AxiosPromise<UserVO> => {
    return request({
        url: '/system/user/' + id,
        method: 'get'
    });
};

/**
 * 新增用户
 * @param data
 */
export const addUser = (data: UserForm) => {
    return request({
        url: '/system/user',
        method: 'post',
        data: data
    });
};

/**
 * 修改用户
 * @param data
 */
export const updateUser = (data: UserForm) => {
    return request({
        url: '/system/user',
        method: 'put',
        data: data
    });
};

/**
 * 删除用户
 * @param id
 */
export const delUser = (id: string | number | Array<string | number>) => {
    return request({
        url: '/system/user/' + id,
        method: 'delete'
    });
};

/**
 * 根据id查询用户
 * @param id
 */
export const queryByIds = (ids: Array<string | number>) => {
    return request({
        url: '/sys/user/queryByIds',
        method: 'post',
        data: { ids: ids }
    });
};

/**
 * 同步oa用户
 * @param id
 */
export const syncOaApi = () => {
    return request({
        url: '/sys/user/syncOa',
        method: 'post',
    });
};


/**
 * 同步oa用户
 * @param id
 */
export const getUserProfile = () => {
    return request({
        url: '/sys/user/syncOa',
        method: 'post',
    });
};
/**
 * 同步oa用户
 * @param id
 */
export const uploadAvatar = (param: any) => {
    return request({
        url: '/sys/user/syncOa',
        method: 'post',
    });
};
/**
 * 同步oa用户
 * @param id
 */
export const updateUserProfile = (user: UserVO) => {
    return request({
        url: '/sys/user/updateUserInfo',
        method: 'post',
        data: user
    });
};

/**
 * 根据角色id查询角色对应的菜单id
 * @param id
 */
export const setUserRole = (data: { rids: (number | string)[], uid: string | number }) => {
    return request({
        url: '/sys/role/manage/setUserRole',
        method: 'post',
        data: data
    });
}


/**
 * 用户密码重置
 * @param oldPassword 旧密码
 * @param newPassword 新密码
 */
export const updateUserPwd = (form: ResetPwdForm) => {

    return request({
        url: '/lingcun/modifyPass',
        method: 'post',
        data: form
    });
};

/**
 * 个性化设置
 */
export const getPersonalize = () => {

    return request({
        url: '/personalize/column/getList',
        method: 'post',
    });
};

/**
 * 个性化设置
 */
export const savePersonalize = (data) => {

    return request({
        url: '/personalize/column/save',
        method: 'post',
        data: data
    });
};
//   personalize/column/getPersonalize 跟进code获取个性化
export const getPersonalizeByCode = (code: string) => {
    return request({
        url: '/personalize/column/getPersonalize',
        method: 'post',
        data: { code: code }
    });
};


export const resetPrePwd = (id: string | number) => {
    return request({
        url: '/sys/user/resetPassword',
        method: 'post',
        data: { userId: id }
    });
};

/**
 * 冻结/解冻用户
 * @param ids 用户ID数组
 * @param isFreeze 1:冻结，0:解冻
 */
export const markFreeze = (ids: Array<string | number>, isFreeze: number) => {
    return request({
        url: '/sys/user/markFreeze',
        method: 'post',
        data: { ids, isFreeze }
    });
};
