import { request } from '@/api';
import type {
  RoleFormParams,
  DeleteRoleParams,
  SetRolePermissionParams,
  GetRolePermissionParams,
  RoleListResponse,
  PermissionIdsResponse
} from '@/api/types/system/role';

/**
 * 获取角色列表
 * @returns Promise<RoleListResponse> 角色列表数据
 */
export async function getRoleApi(): Promise<RoleListResponse> {
  return request.get<RoleListResponse>('/roles/list');
}

/**
 * 创建角色
 * @param params 角色名称、标题
 * @returns Promise<void>
 */
export async function createRoleApi(params: RoleFormParams): Promise<void> {
  return request.post<void>('/roles/create', params);
}

/**
 * 编辑角色
 * @param params 角色ID、名称、标题
 * @returns Promise<void>
 */
export async function editRoleApi(params: RoleFormParams): Promise<void> {
  return request.post<void>('/roles/edit', params);
}

/**
 * 删除角色
 * @param params 角色ID
 * @returns Promise<void>
 */
export async function deleteRoleApi(params: DeleteRoleParams): Promise<void> {
  return request.post<void>('/roles/del', params);
}

/**
 * 获取角色权限
 * @param params 角色ID
 * @returns Promise<PermissionIdsResponse> 权限ID数组
 */
export async function getRolePermissionApi(params: GetRolePermissionParams): Promise<PermissionIdsResponse> {
  return request.get<PermissionIdsResponse>('/roles/getPermission', { id: params.id });
}

/**
 * 设置角色权限
 * @param params 角色ID + 权限ID列表（逗号分隔字符串）
 * @returns Promise<void>
 */
export async function setRolePermissionApi(params: SetRolePermissionParams): Promise<void> {
  return request.post<void>('/roles/setPermission', params);
}
