using System;

namespace Valg.EVA.Skanning.UserInterfaceElements.Login
{
    public class LoginWindowLoginResult
    {
        public static readonly LoginWindowLoginResult LoginFromEmergencyMode = new LoginWindowLoginResult(true, false);
        public static readonly LoginWindowLoginResult LoginFromIdPorten = new LoginWindowLoginResult(true, false);
        public static readonly LoginWindowLoginResult ErrorInToken = new LoginWindowLoginResult(false, true);

        public static LoginWindowLoginResult CreateResultWithError(Exception exception)
        {
            return new LoginWindowLoginResult(false, false)
            {
                Exception = exception
            };
        }
      
        private LoginWindowLoginResult(bool isTokenValid, bool isRootCertificateMissing)
        {
            IsTokenValid = isTokenValid;
            IsRootCertificateMissing = isRootCertificateMissing;
        }

        public Exception Exception { get; set; }

        public bool IsTokenValid { get; }

        public bool IsRootCertificateMissing { get; }

        public bool HasErrors => Exception != null
                                 || !IsTokenValid
                                 || IsRootCertificateMissing;
    }
}
