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

import dev.lions.unionflow.server.api.dto.gouvernance.EchelonOrganigrammeDTO;
import dev.lions.unionflow.server.service.gouvernance.EchelonOrganigrammeService;

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/gouvernance/organigramme")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class EchelonOrganigrammeResource {

    @Inject
    EchelonOrganigrammeService echelonOrganigrammeService;

    @POST
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION" })
    public Response creerEchelon(@Valid EchelonOrganigrammeDTO dto) {
        EchelonOrganigrammeDTO response = echelonOrganigrammeService.creerEchelon(dto);
        return Response.status(Response.Status.CREATED).entity(response).build();
    }

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

    @GET
    @Path("/organisation/{organisationId}")
    @RolesAllowed({ "ADMIN", "SUPER_ADMIN", "ADMIN_ORGANISATION", "MEMBRE", "USER" })
    public Response getOrganigrammeByOrganisation(@PathParam("organisationId") UUID organisationId) {
        List<EchelonOrganigrammeDTO> response = echelonOrganigrammeService
                .getOrganigrammeByOrganisation(organisationId);
        return Response.ok(response).build();
    }
}
