import request from '/@/utils/request';
import { AxiosPromise } from 'axios';
import type { IUser } from './types/index.type';

export interface UsersByROleGroupParams {
	clientCode: string;
	roleClasses: string[]
	isFilterDisabledUser?: 0 | 1 // 0:不过滤 1:过滤
}

export function Add(params: string) {
	return request({
		url: '/user/info/add',
		method: 'post',
		data: params,
	});
}
export function update(params: string) {
	return request({
		url: '/user/info/update',
		method: 'post',
		data: params,
	});
}
export function deleteId(params: string) {
	return request({
		url: '/user/info/delete',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}
export function list(params: object) {
    return request({
      url: '/user/info/list',
      method: 'post',
      params
    })
}
export function listUsersInClient(params: string) {
	return request({
		url: '/user/info/listUsersInClient',
		method: 'post',
		data: params,
	});
}
export function getUsersByRoleCode(params: string) {
	return request({
		url: '/user/info/getUsersByRoleCode',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}

/**
 * 根据角色获取用户列表
 * @param params 
 * @returns 
 */
export function getUsersByRoleGroup(params: UsersByROleGroupParams) :AxiosPromise<IUser[]> {
	return request({
		url: '/user/info/getUsersByRoleGroup',
		method: 'post',
		data: params,
	});
}
export function sendValidateCode(params: string) {
	return request({
		url: '/user/info/sendValidateCode',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}
export function forgetPassword(params: Object) {
	return request({
		url: '/user/info/forgetPassword',
		method: 'post',
		data: params,
	});
}
export function confirmClient(params: string) {
	return request({
		url: '/user/info/confirmClient',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: params,
	});
}
export function passwordCheck(params: object) {
	return request({
		url: '/user/info/passwordCheck',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		params,
	});
}
export function updateSortOrder(params: object) {
	return request({
		url: '/user/info/updateSortOrder',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		params,
	});
}
export function clearSchedulesByUser(params: object) {
	return request({
		url: '/staff/schedule/clearSchedulesByUser',
		method: 'post',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		params,
	});
}



/**
 * 重置用户密码
 * @param userCode 
 * @returns 
 */
export function apiResetPwd(userCode: string) {
	return request({
		url: "/user/info/resetPassword",
		method: "post",
		headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
		data: `userCode=${userCode}`
	})
}