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.WorkshopRestService;
import com.gbcm.server.api.dto.workshop.WorkshopDTO;
import com.gbcm.server.api.dto.common.PagedResponseDTO;

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

@Named("workshopBean")
@RequestScoped
public class WorkshopBean implements Serializable {

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

    @Inject
    private WorkshopRestService workshopRestService;

    public List<WorkshopDTO> getWorkshops() {
        try {
            logger.info("Récupération de la liste des ateliers");
            PagedResponseDTO<WorkshopDTO> pagedResponse = workshopRestService.getWorkshops(0, 50, null, null, null,
                    null, null);
            return pagedResponse.getContent();
        } catch (Exception e) {
            logger.severe("Erreur lors de la récupération des ateliers: " + e.getMessage());
            return new ArrayList<>();
        }
    }
}
