using projet.modele;

namespace projet.dal
{
    public class ResponsableAccess
    {
        private readonly Access access;

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

        public bool ConnecterResponsable(Responsable responsable)
        {
            if(access.Manager != null)
            {
                string req = "SELECT * FROM responsable WHERE login = @login AND pwd = SHA2(@pwd, 256);";
                var parameters = new Dictionary<string, object>
                {
                    { "@login", responsable.Login },
                    { "@pwd", responsable.Pwd }
                };
                try
                {
                    List<Object[]> result = access.Manager.ReqSelect(req, parameters);
                    if(result != null)
                    {
                        return (result.Count > 0);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Erreur lors de la connexion à la base de données.");
                    Environment.Exit(0);
                }
                return false;
            }
            return false;
        }
    }
}
