using projet.modele;
namespace projet.dal
{
    public class ServiceAccess
    {
        private readonly Access access;

        public ServiceAccess()
        {
            access = Access.GetInstance();
        }

        public List<Service> GetAllServices()
        {
            List<Service> serviceList = new List<Service>();
            if (access.Manager != null)
            {
                string req = "SELECT * FROM service ORDER BY nom;";
                try
                {
                    List<Object[]> resultats = access.Manager.ReqSelect(req);
                    if (resultats != null)
                    {
                        foreach (Object[] resultat in resultats)
                        {
                            Service service = new Service(
                                Convert.ToInt32(resultat[0]), // IdService
                                Convert.ToString(resultat[1]) // Nom
                            );
                            serviceList.Add(service);
                        }
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Erreur lors de la récupération des données des services.");
                    Environment.Exit(0);
                }
            }
            return serviceList;
        }
    }
}
