package dev.lions.unionflow.server.resource.collectefonds;

import dev.lions.unionflow.server.api.dto.collectefonds.CampagneCollecteResponse;
import dev.lions.unionflow.server.api.dto.collectefonds.ContributionCollecteDTO;
import dev.lions.unionflow.server.service.collectefonds.CampagneCollecteService;

import dev.lions.unionflow.server.security.RequiresModule;
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/collectefonds/campagnes")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequiresModule("COLLECTE_FONDS")
public class CampagneCollecteResource {

    @Inject
    CampagneCollecteService campagneCollecteService;

    @GET
    @Path("/{id}")
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MEMBRE", "USER" })
    public Response getCampagneById(@PathParam("id") UUID id) {
        CampagneCollecteResponse response = campagneCollecteService.getCampagneById(id);
        return Response.ok(response).build();
    }

    @GET
    @Path("/organisation/{organisationId}")
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION" })
    public Response getCampagnesByOrganisation(@PathParam("organisationId") UUID organisationId) {
        List<CampagneCollecteResponse> response = campagneCollecteService.getCampagnesByOrganisation(organisationId);
        return Response.ok(response).build();
    }

    @POST
    @Path("/{id}/contribuer")
    @RolesAllowed({ "MEMBRE", "USER" })
    public Response contribuer(@PathParam("id") UUID id, @Valid ContributionCollecteDTO dto) {
        ContributionCollecteDTO response = campagneCollecteService.contribuer(id, dto);
        return Response.status(Response.Status.CREATED).entity(response).build();
    }
}
