import request from "@/utils/request";

class RoleAPI {
  /** 获取角色分页数据 */
  static getPage(queryParams?: RolePageQuery) {
    return request<any, PageResult<RoleDTO[]>>({
      url: `/api/role/getPageRole`,
      method: "get",
      params: queryParams,
    });
  }

  static getAllRole() {
    return request<any, RoleDTO[]>({
      url: `/api/role/getRoleList`,
      method: "get",
    });
  }

  /** 添加角色 */
  static addRole(data: RoleForm) {
    return request<any, string>({
      url: `api/role/addRole`,
      method: "post",
      data: data,
    });
  }

  /**
   * 更新角色
   *
   * @param id 角色ID
   * @param data 角色表单数据
   */
  static updateRole(data: RoleForm) {
    return request({
      url: `/api/role/updateRole`,
      method: "post",
      data: data,
    });
  }

  static getMenuList() {
    return request<any, MenuDTO[]>({
      url: `/api/menus/getList`,
      method: "get",
    });
  }

  static queryRoleById(data: { roleId: number }) {
    return request<any, MenuRoleDTO[]>({
      url: `/api/role/getMenusRole`,
      method: "get",
      params: data,
    });
  }
}

export default RoleAPI;

/** 角色分页查询参数 */
export interface RolePageQuery extends PageQuery {
  /** 搜索关键字 */
  roleName?: string;
}

/** 角色分页对象 */
export interface RoleDTO {
  createTime?: string;
  createUserId?: number;
  createUserName?: string;
  id: number;
  isDeleted?: boolean;
  roleCode?: string;
  roleName?: string;
  state?: number;
  updateTime?: string;
  updateUserId?: number;
  updateUserName?: string;
}

/** 角色表单对象 */
export interface RoleForm {
  id?: number;
  roleName?: string;
  list?: Menu[];
  isDeleted?: boolean;
}

export interface Menu {
  menusId?: number;
  state?: number;
}

export interface MenuDTO {
  createTime?: string;
  createUserId?: number;
  createUserName?: string;
  id?: number;
  name?: string;
  note?: string;
  parentId?: string;
  permission?: string;
  sort?: number;
  state?: string;
  type?: number;
  updateTime?: string;
  updateUserId?: number;
  updateUserName?: string;
  url?: string;
}
export interface MenuRoleDTO {
  createTime?: string;
  createUserId?: number;
  id?: number;
  menusId?: number;
  menusName?: string;
  roleId?: number;
  state?: number;
  updateTime?: string;
  updateUserId?: number;
}
