import request from '@/utils/request';
import {AxiosPromise} from 'axios';
import {RoleVO, RoleForm, RoleQuery} from '@/api/system/role/types';

/**
 * 查询角色管理列表
 * @param query
 * @returns {*}
 */

export const listRole = (query?: RoleQuery): AxiosPromise<{records:RoleVO[]}> => {
    return request({
        url: '/sys/role/manage/pagelist',
        method: 'post',
        data: query
    });
};


/**
 * 新增角色管理
 * @param data
 */
export const addRole = (data: RoleForm) => {
    return request({
        url: '/sys/role/manage/save',
        method: 'post',
        data: data
    });
};

/**
 * 修改角色管理
 * @param data
 */
export const updateRole = (data: RoleForm) => {
    return request({
        url: '/system/role',
        method: 'put',
        data: data
    });
};

/**
 * 删除角色管理
 * @param id
 */
export const delRole = (id: string | number | Array<string | number>) => {
    let ids = Array.isArray(id) ? [id] : id
    return request({
        url: '/sys/role/manage/delete',
        method: 'post',
        data: {ids: ids }
    });
};
/**
 * 根据角色id查询角色对应的菜单id
 * @param id
 */
export const getRoleMenuTreeselect= (id: string | number)=>{
    return request({
        url: '/sys/role/manage/getRoleMenuId',
        method: 'post',
        data: {roleId: id }
    });

}
/*
getH5RoleMenuId
*/
export const getH5RoleMenuId= (id: string | number)=>{
    return request({
        url: '/sys/role/manage/getH5RoleMenuId',
        method: 'post',
        data: {roleId: id }
    });
}
/**
 * 根据角色id查询角色对应的菜单id
 * @param id
 */
export const bindDeptRole= (data: RoleForm)=>{
    return request({
        url: '/sys/role/manage/save',
        method: 'post',
        data: data
    });
}
/**
 * 查询角色管理详细
 * @param id
 */
export const getDeptsByRole = (id: string | number)=> {
    return request({
        url: '/sys/role/manage/getRoleDeptId',
        method: 'post',
        data: {roleId: id}
    });
};

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

/**
 * 启用禁用角色
 * @param id
 */
export const enableRole= (data: { enable: boolean, id: string|number })=>{
    return request({
        url: '/sys/role/manage/enable',
        method: 'post',
        data: data
    });
}

/**
 * 绑定角色菜单
 * @param data
 */
export const bindAppRoleMenu= (data: { roleId: string|number, menuls: string|number[], isApp: number })=>{
    return request({
        url: '/sys/role/manage/bind_role_menu',
        method: 'post',
        data: data
    });
}
