package dev.lions.unionflow.server.resource.mutuelle.parts;

import dev.lions.unionflow.server.api.dto.mutuelle.parts.ComptePartsSocialesRequest;
import dev.lions.unionflow.server.api.dto.mutuelle.parts.ComptePartsSocialesResponse;
import dev.lions.unionflow.server.api.dto.mutuelle.parts.TransactionPartsSocialesRequest;
import dev.lions.unionflow.server.api.dto.mutuelle.parts.TransactionPartsSocialesResponse;
import dev.lions.unionflow.server.security.RequiresModule;
import dev.lions.unionflow.server.service.mutuelle.parts.ComptePartsSocialesService;
import jakarta.annotation.security.RolesAllowed;
import jakarta.inject.Inject;
import jakarta.validation.Valid;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;

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

@Path("/api/v1/parts-sociales/comptes")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequiresModule("EPARGNE")
public class ComptePartsSocialesResource {

    @Inject
    ComptePartsSocialesService service;

    @POST
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
    public Response ouvrirCompte(@Valid ComptePartsSocialesRequest request) {
        ComptePartsSocialesResponse resp = service.ouvrirCompte(request);
        return Response.status(Response.Status.CREATED).entity(resp).build();
    }

    @POST
    @Path("/transactions")
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
    public Response enregistrerTransaction(@Valid TransactionPartsSocialesRequest request) {
        TransactionPartsSocialesResponse resp = service.enregistrerSouscription(request);
        return Response.status(Response.Status.CREATED).entity(resp).build();
    }

    @GET
    @Path("/{id}")
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
    public Response getById(@PathParam("id") UUID id) {
        return Response.ok(service.getById(id)).build();
    }

    @GET
    @Path("/membre/{membreId}")
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
    public Response getByMembre(@PathParam("membreId") UUID membreId) {
        List<ComptePartsSocialesResponse> list = service.getByMembre(membreId);
        return Response.ok(list).build();
    }

    @GET
    @Path("/organisation/{orgId}")
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP"})
    public Response getByOrganisation(@PathParam("orgId") UUID orgId) {
        List<ComptePartsSocialesResponse> list = service.getByOrganisation(orgId);
        return Response.ok(list).build();
    }

    @GET
    @Path("/{id}/transactions")
    @RolesAllowed({"ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MUTUELLE_RESP", "MEMBRE", "USER"})
    public Response getTransactions(@PathParam("id") UUID id) {
        List<TransactionPartsSocialesResponse> list = service.getTransactions(id);
        return Response.ok(list).build();
    }
}
