package dev.lions.unionflow.client.service;

import dev.lions.unionflow.server.api.dto.finance_workflow.request.ApproveTransactionRequest;
import dev.lions.unionflow.server.api.dto.finance_workflow.request.CreateBudgetRequest;
import dev.lions.unionflow.server.api.dto.finance_workflow.request.RejectTransactionRequest;
import dev.lions.unionflow.server.api.dto.finance_workflow.response.BudgetResponse;
import dev.lions.unionflow.server.api.dto.finance_workflow.response.TransactionApprovalResponse;
import org.eclipse.microprofile.rest.client.annotation.RegisterClientHeaders;
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

import java.util.List;
import java.util.Map;
import java.util.UUID;

@RegisterRestClient(configKey = "unionflow-api")
@RegisterClientHeaders(dev.lions.unionflow.client.security.AuthHeaderFactory.class)
@Path("/api/finance")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface FinanceApprovalService {

    // --- Approbations ---

    @GET
    @Path("/approvals/pending")
    List<TransactionApprovalResponse> obtenirApprobationsEnAttente(
        @QueryParam("organizationId") UUID organizationId,
        @QueryParam("page") @DefaultValue("0") int page,
        @QueryParam("size") @DefaultValue("20") int size
    );

    @GET
    @Path("/approvals/{approvalId}")
    TransactionApprovalResponse obtenirApprobation(@PathParam("approvalId") UUID approvalId);

    @POST
    @Path("/approvals/{approvalId}/approve")
    TransactionApprovalResponse approuver(
        @PathParam("approvalId") UUID approvalId,
        ApproveTransactionRequest request
    );

    @POST
    @Path("/approvals/{approvalId}/reject")
    TransactionApprovalResponse rejeter(
        @PathParam("approvalId") UUID approvalId,
        RejectTransactionRequest request
    );

    @GET
    @Path("/approvals/history")
    List<TransactionApprovalResponse> obtenirHistorique(
        @QueryParam("organizationId") UUID organizationId,
        @QueryParam("startDate") String startDate,
        @QueryParam("endDate") String endDate,
        @QueryParam("status") String status,
        @QueryParam("page") @DefaultValue("0") int page,
        @QueryParam("size") @DefaultValue("20") int size
    );

    @GET
    @Path("/approvals/count/pending")
    Map<String, Long> compterEnAttente(@QueryParam("organizationId") UUID organizationId);

    // --- Budgets ---

    @GET
    @Path("/budgets")
    List<BudgetResponse> listerBudgets(
        @QueryParam("organizationId") UUID organizationId,
        @QueryParam("page") @DefaultValue("0") int page,
        @QueryParam("size") @DefaultValue("20") int size
    );

    @GET
    @Path("/budgets/{budgetId}")
    BudgetResponse obtenirBudget(@PathParam("budgetId") UUID budgetId);

    @POST
    @Path("/budgets")
    BudgetResponse creerBudget(CreateBudgetRequest request);

    @PUT
    @Path("/budgets/{budgetId}")
    BudgetResponse modifierBudget(@PathParam("budgetId") UUID budgetId, CreateBudgetRequest request);

    @DELETE
    @Path("/budgets/{budgetId}")
    void supprimerBudget(@PathParam("budgetId") UUID budgetId);

    // --- Statistiques workflow ---

    @GET
    @Path("/stats")
    Map<String, Object> obtenirStatistiques(
        @QueryParam("organizationId") UUID organizationId,
        @QueryParam("startDate") String startDate,
        @QueryParam("endDate") String endDate
    );
}
