import { http } from "@/utils/http";
import { baseUrlApi } from "../utils";

export interface BasicResponseModel<T = any> {
  code: number;
  msg: string;
  data: T;
}

export interface BasicPageResponseModel<T = any> {
  code: number;
  msg: string;
  rows: T;
  total: number;
}

export interface DeptTreeModel<T = any> {
  code: number;
  msg: string;
  depts: T;
  checkedKeys: number[];
}

/**
 * 获取角色列表
 * @param query
 */
export const getSystemRoleList = (query?: object) => {
  return http.request<BasicPageResponseModel>(
    "post",
    baseUrlApi("system/role/list"),
    { params: query }
  );
};

/**
 * 修改角色状态
 * @param roleId
 * @param status
 */
export const changeRoleStatus = (roleId: number, status: string) => {
  const data = {
    roleId,
    status
  };
  return http.request<BasicResponseModel>(
    "put",
    baseUrlApi("system/role/changeStatus"),
    { data }
  );
};

/**
 * 获取角色部门树
 * @param id
 */
export const getSystemRoleDeptTree = (id?: string) => {
  return http.request<DeptTreeModel>(
    "get",
    baseUrlApi(`system/role/deptTree/${id}`)
  );
};

/**
 * 添加角色
 * @param data
 */
export const addSystemRole = (data: object) => {
  return http.request<BasicResponseModel>("post", baseUrlApi("system/role"), {
    data
  });
};

/**
 * 修改角色
 * @param data
 */
export const updateSystemRole = (data: object) => {
  return http.request<BasicResponseModel>("put", baseUrlApi("system/role"), {
    data
  });
};

/**
 * 删除角色
 * @param id
 */
export const deleteSystemRole = (id: string) => {
  return http.request<BasicResponseModel>(
    "delete",
    baseUrlApi(`system/role/${id}`)
  );
};

/**
 * 根据ID获取角色详细信息
 * @param id
 */
export const getSystemRoleById = (id?: string) => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi(`system/role/${id}`)
  );
};

/**
 * 修改角色数据权限
 * @param data
 */
export const putSystemRoleDataScope = (data: object) => {
  return http.request<BasicResponseModel>(
    "put",
    baseUrlApi("system/role/dataScope"),
    { data }
  );
};

/**
 * 获取角色选择框列表
 */
export const getSystemRoleOptionselect = () => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi("system/role/optionselect")
  );
};
