import httpClient from '@/utils/http';

import {
  ControllerResponse,
  ModelAssignMenuRequest,
  ModelCreateSysRoleRequest,
  ModelSysMenu,
  ModelSysRole,
  ModelUpdateSysRoleRequest
} from './data-contracts';
export default {
  /**
   * @description 创建新的系统角色
   */
  roleManagementCreate: (role: ModelCreateSysRoleRequest) => {
    return httpClient.post<
      ControllerResponse & {
        /** 系统角色信息模型 */
        data?: ModelSysRole;
      }
    >(`/sys/role-management`, { params: role });
  },
  /**
   * @description 获取所有系统角色的列表信息
   */
  roleManagementList: () => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelSysRole[];
      }
    >(`/sys/role-management`);
  },
  /**
   * @description 根据角色ID获取特定系统角色的详细信息
   */
  roleManagementDetail: (rid: number) => {
    return httpClient.get<
      ControllerResponse & {
        /** 系统角色信息模型 */
        data?: ModelSysRole;
      }
    >(`/sys/role-management/${rid}`);
  },
  /**
   * @description 根据ID更新系统角色信息
   */
  roleManagementUpdate: (rid: string, role: ModelUpdateSysRoleRequest) => {
    return httpClient.put<
      ControllerResponse & {
        /** 系统角色信息模型 */
        data?: ModelSysRole;
      }
    >(`/sys/role-management/${rid}`, { params: role });
  },
  /**
   * @description 根据ID删除系统角色（软删除）
   */
  roleManagementDelete: (rid: number) => {
    return httpClient.delete<
      ControllerResponse & {
        data?: string;
      }
    >(`/sys/role-management/${rid}`);
  },
  /**
   * @description 为系统角色分配权限
   */
  roleManagementPermissionsCreate: (rid: string, req: ModelAssignMenuRequest) => {
    return httpClient.post<
      ControllerResponse & {
        data?: string;
      }
    >(`/sys/role-management/${rid}/permissions`, { params: req });
  },
  /**
   * @description 获取系统角色的权限列表
   */
  roleManagementPermissionsDetail: (rid: number) => {
    return httpClient.get<
      ControllerResponse & {
        data?: ModelSysMenu[];
      }
    >(`/sys/role-management/${rid}/permissions`);
  },
  /**
   * @description 移除系统角色的权限
   */
  roleManagementPermissionsDelete: (
    rid: string,
    query: {
      /** 菜单ID列表,用逗号分隔 */
      menu_ids: string;
    }
  ) => {
    return httpClient.delete<
      ControllerResponse & {
        data?: string;
      }
    >(`/sys/role-management/${rid}/permissions`, { query: query });
  }
};
