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

import dev.lions.unionflow.server.api.dto.culte.DonReligieuxDTO;
import dev.lions.unionflow.server.service.culte.DonReligieuxService;

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/culte/dons")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequiresModule("CULTE_DONS")
public class DonReligieuxResource {

    @Inject
    DonReligieuxService donReligieuxService;

    @POST
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MEMBRE", "USER" })
    public Response enregistrerDon(@Valid DonReligieuxDTO dto) {
        DonReligieuxDTO response = donReligieuxService.enregistrerDon(dto);
        return Response.status(Response.Status.CREATED).entity(response).build();
    }

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

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