package com.gbcm.client.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import com.gbcm.client.service.CoachRestService;
import com.gbcm.server.api.dto.coach.CoachDTO;
import com.gbcm.server.api.dto.common.PagedResponseDTO;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.inject.Named;

@Named("coachBean")
@RequestScoped
public class CoachBean implements Serializable {

    private static final Logger logger = Logger.getLogger(CoachBean.class.getName());

    @Inject
    private CoachRestService coachRestService;

    public List<CoachDTO> getCoaches() {
        try {
            logger.info("Récupération de la liste des coachs depuis le serveur backend");
            PagedResponseDTO<CoachDTO> pagedResponse = coachRestService.getCoaches(0, 50, null, null, null, false,
                    null);
            return pagedResponse.getContent();
        } catch (Exception e) {
            logger.severe("Erreur lors de la récupération des coachs: " + e.getMessage());
            return new ArrayList<>();
        }
    }
}
