package dev.lions.unionflow.server.resource;

import dev.lions.unionflow.server.security.OrganisationContextHolder;
import dev.lions.unionflow.server.service.compliance.ComplianceDashboardService;
import io.quarkus.security.Authenticated;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
import java.util.UUID;

/** Endpoint du tableau de bord de conformité (P1-NEW-7). */
@Path("/api/compliance/dashboard")
@Authenticated
public class ComplianceDashboardResource {

  @Inject ComplianceDashboardService service;
  @Inject OrganisationContextHolder context;

  @GET
  @Produces(MediaType.APPLICATION_JSON)
  @RolesAllowed({"PRESIDENT", "TRESORIER", "COMPLIANCE_OFFICER", "CONTROLEUR_INTERNE",
      "ADMIN_ORGANISATION", "SUPER_ADMIN"})
  public ComplianceDashboardService.ComplianceSnapshot snapshotCurrent() {
    UUID orgId = context.getOrganisationId();
    if (orgId == null) {
      throw new IllegalStateException("Aucune organisation active dans le contexte");
    }
    return service.snapshot(orgId);
  }

  @GET
  @Path("/{organisationId}")
  @Produces(MediaType.APPLICATION_JSON)
  @RolesAllowed({"SUPER_ADMIN"})
  public ComplianceDashboardService.ComplianceSnapshot snapshotOf(@PathParam("organisationId") UUID orgId) {
    return service.snapshot(orgId);
  }
}
