import axiosInstance from '../utils/axios';

// 角色 VO
export interface RoleVO {
  id?: number;
  name: string;
  code: string;
  sort: number;
  status: number;
  type: number;
  dataScope: number;
  dataScopeDeptIds?: number[];
  remark?: string;
  createTime?: Date;
}

// 更新状态请求 VO
export interface UpdateStatusReqVO {
  id: number;
  status: number;
}

// 分页参数类型
export interface PageParam {
  pageNo?: number;
  pageSize?: number;
  name?: string;
  code?: string;
  status?: number;
  createTime?: string[];
  [key: string]: any;
}

// 分页响应类型
export interface PageResponse<T> {
  list: T[];
  total: number;
}

// 角色管理 API
export const roleApi = {
  // 查询角色列表（分页）
  getRolePage: (params?: PageParam) => {
    return axiosInstance.get<PageResponse<RoleVO>>('/system/role/page', { params });
  },

  // 查询角色（精简）列表
  getSimpleRoleList: () => {
    return axiosInstance.get<RoleVO[]>('/system/role/simple-list');
  },

  // 查询角色详情
  getRole: (id: number) => {
    return axiosInstance.get<RoleVO>(`/system/role/get?id=${id}`);
  },

  // 新增角色
  createRole: (data: RoleVO) => {
    return axiosInstance.post('/system/role/create', data);
  },

  // 修改角色
  updateRole: (data: RoleVO) => {
    return axiosInstance.put('/system/role/update', data);
  },

  // 修改角色状态
  updateRoleStatus: (data: UpdateStatusReqVO) => {
    return axiosInstance.put('/system/role/update-status', data);
  },

  // 删除角色
  deleteRole: (id: number) => {
    return axiosInstance.delete(`/system/role/delete?id=${id}`);
  },

  // 导出角色
  exportRole: (params?: PageParam) => {
    return axiosInstance.get('/system/role/export-excel', { 
      params,
      responseType: 'blob'
    });
  },

  // 获取角色菜单权限列表
  getRoleMenuList: (roleId: number) => {
    return axiosInstance.get<number[]>(`/system/permission/list-role-menus?roleId=${roleId}`);
  },

  // 分配角色菜单权限
  assignRoleMenu: (params: {
    roleId: number;
    menuIds: number[];
  }) => {
    return axiosInstance.post('/system/permission/assign-role-menu', params);
  },

  // 分配角色数据权限
  assignRoleDataScope: (params: {
    roleId: number;
    dataScope: number;
    dataScopeDeptIds?: number[];
  }) => {
    return axiosInstance.post('/system/permission/assign-role-data-scope', params);
  },
};


