import { Controller, Get } from "@nestjs/common";
import { IamService } from "./iam.service.js";
import {
  Permissions,
  RequirePermission,
} from "../middleware/permission.guard.js";

/**
 * RBAC 管理端点：角色/权限查询（admin-portal 使用）。
 *
 * 路径前缀：/v1/iam（I7 裁决）
 */
@Controller("v1/iam")
export class RbacController {
  constructor(private readonly service: IamService) {}

  @Get("roles")
  @RequirePermission(Permissions.IAM_ROLE_MANAGE)
  async roles(): Promise<{ success: true; data: unknown[] }> {
    const data = await this.service.getAllRoles();
    return { success: true as const, data };
  }

  @Get("permissions")
  @RequirePermission(Permissions.IAM_ROLE_MANAGE)
  async permissions(): Promise<{ success: true; data: unknown[] }> {
    const data = await this.service.getAllPermissions();
    return { success: true as const, data };
  }
}
