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

import dev.lions.unionflow.server.api.dto.agricole.CampagneAgricoleDTO;
import dev.lions.unionflow.server.service.agricole.CampagneAgricoleService;

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/agricole/campagnes")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequiresModule("AGRICULTURE")
public class CampagneAgricoleResource {

    @Inject
    CampagneAgricoleService campagneAgricoleService;

    @POST
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "COOP_RESP" })
    public Response creerCampagne(@Valid CampagneAgricoleDTO dto) {
        CampagneAgricoleDTO response = campagneAgricoleService.creerCampagne(dto);
        return Response.status(Response.Status.CREATED).entity(response).build();
    }

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

    @GET
    @Path("/cooperative/{organisationId}")
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "COOP_RESP" })
    public Response getCampagnesByCooperative(@PathParam("organisationId") UUID organisationId) {
        List<CampagneAgricoleDTO> response = campagneAgricoleService.getCampagnesByCooperative(organisationId);
        return Response.ok(response).build();
    }
}
