package com.cameleer.server.app.controller;

import com.cameleer.server.core.rbac.RbacService;
import com.cameleer.server.core.rbac.RbacStats;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Admin endpoint for RBAC statistics.
 * Protected by {@code ROLE_ADMIN}.
 */
@RestController
@RequestMapping("/api/v1/admin/rbac")
@Tag(name = "RBAC Stats", description = "RBAC statistics (ADMIN only)")
@PreAuthorize("hasRole('ADMIN')")
public class RbacStatsController {

    private final RbacService rbacService;

    public RbacStatsController(RbacService rbacService) {
        this.rbacService = rbacService;
    }

    @GetMapping("/stats")
    @Operation(summary = "Get RBAC statistics for the dashboard")
    @ApiResponse(responseCode = "200", description = "RBAC stats returned")
    public ResponseEntity<RbacStats> getStats() {
        return ResponseEntity.ok(rbacService.getStats());
    }
}
