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

import dev.lions.unionflow.server.api.dto.registre.AgrementProfessionnelDTO;
import dev.lions.unionflow.server.service.registre.AgrementProfessionnelService;

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/registre/agrements")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequiresModule("REGISTRE_AGREMENT")
public class AgrementProfessionnelResource {

    @Inject
    AgrementProfessionnelService agrementProfessionnelService;

    @POST
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "REGISTRE_RESP" })
    public Response enregistrerAgrement(@Valid AgrementProfessionnelDTO dto) {
        AgrementProfessionnelDTO response = agrementProfessionnelService.enregistrerAgrement(dto);
        return Response.status(Response.Status.CREATED).entity(response).build();
    }

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

    @GET
    @Path("/membre/{membreId}")
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MEMBRE", "USER" })
    public Response getAgrementsByMembre(@PathParam("membreId") UUID membreId) {
        List<AgrementProfessionnelDTO> response = agrementProfessionnelService.getAgrementsByMembre(membreId);
        return Response.ok(response).build();
    }

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