package dev.lions.unionflow.client.service;

import dev.lions.unionflow.client.security.AuthHeaderFactory;
import dev.lions.unionflow.server.api.dto.audit.response.AuditTrailOperationResponse;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import java.util.List;
import java.util.UUID;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

/**
 * Client REST de lecture audit trail (Sprint 11 ⇄ backend Sprint 10 CQRS read).
 */
@RegisterRestClient(configKey = "unionflow-api")
@RegisterClientHeaders(AuthHeaderFactory.class)
@Path("/api/audit-trail")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface AuditTrailRestClient {

  @GET
  @Path("/by-user/{userId}")
  List<AuditTrailOperationResponse> parUtilisateur(
      @PathParam("userId") UUID userId,
      @QueryParam("from") String from,
      @QueryParam("to") String to);

  @GET
  @Path("/by-entity/{type}/{id}")
  List<AuditTrailOperationResponse> historique(
      @PathParam("type") String entityType, @PathParam("id") UUID entityId);

  @GET
  @Path("/by-organisation/{orgId}")
  List<AuditTrailOperationResponse> parOrganisation(@PathParam("orgId") UUID orgId);

  @GET
  @Path("/sod-violations")
  List<AuditTrailOperationResponse> violationsSod();

  @GET
  @Path("/financial/{orgId}")
  List<AuditTrailOperationResponse> operationsFinancieres(
      @PathParam("orgId") UUID orgId,
      @QueryParam("from") String from,
      @QueryParam("to") String to);

  /** Live Activity Feed (Sprint 15) — N opérations les plus récentes selon scope. */
  @GET
  @Path("/recent")
  List<AuditTrailOperationResponse> recent(
      @QueryParam("scope") String scope,
      @QueryParam("orgId") UUID orgId,
      @QueryParam("userId") UUID userId,
      @QueryParam("limit") int limit);
}
