package com.gbcm.client.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
import org.eclipse.microprofile.rest.client.inject.RestClient;

import com.gbcm.server.api.dto.session.CoachingSessionDTO;
import com.gbcm.server.api.dto.common.PagedResponseDTO;
import com.gbcm.server.api.enums.SessionStatus;
import com.gbcm.server.api.enums.ServiceType;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;

@ApplicationScoped
public class CoachingSessionRestService {

    private static final Logger logger = LoggerFactory.getLogger(CoachingSessionRestService.class);

    @Inject
    @RestClient
    private CoachingSessionRestClient sessionRestClient;

    public PagedResponseDTO<CoachingSessionDTO> getCoachingSessions(int page, int size, String sort,
            SessionStatus status, ServiceType serviceType,
            Long coachId, Long clientId, String search) {
        try {
            logger.info("Appel API pour récupérer les sessions");
            return sessionRestClient.getCoachingSessions(page, size, sort, status, serviceType, coachId, clientId,
                    search);
        } catch (Exception e) {
            logger.error("Erreur lors de l'appel API getCoachingSessions: " + e.getMessage(), e);
            throw new RuntimeException("Impossible de récupérer les sessions", e);
        }
    }

    @RegisterRestClient
    @Path("/sessions")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public interface CoachingSessionRestClient {

        @GET
        PagedResponseDTO<CoachingSessionDTO> getCoachingSessions(
                @QueryParam("page") int page,
                @QueryParam("size") int size,
                @QueryParam("sort") String sort,
                @QueryParam("status") SessionStatus status,
                @QueryParam("serviceType") ServiceType serviceType,
                @QueryParam("coachId") Long coachId,
                @QueryParam("clientId") Long clientId,
                @QueryParam("search") String search);
    }
}
