using System;
using System.Configuration;
using Microsoft.VisualBasic;
using Strata.Configuration.Client.Models.Jazz;

namespace Strata.Base.Internal.Encryptors
{

    public class UberEncryptionMethod : IPasswordEncryptionMethod
    {

        public UberEncryptionMethod()
        {

        }

        #region  Methods 

        public static string GetUberMonet(string anOrgPin)
        {
            return GetUberMonet(DateTime.Today, anOrgPin, ConfigurationManager.AppSettings[nameof(StrataJazzOptions.UberMonetKey)]);
        }

        private static string GetUberMonet(DateTime aDate, string anOrgPIN, string aKey)
        {
            var ha = new EncryptionUtils.Hasher(EncryptionUtils.Hasher.Provider.SHA256);

            string lsHashBefore;
            string lsResult;

            lsHashBefore = Strings.Format(aDate, "dd-MM-yyyy") + "-" + anOrgPIN + "-" + aKey;

            var d = new EncryptionUtils.Data(lsHashBefore);

            var dResult = ha.Calculate(d);
            lsResult = Strings.Left(dResult.Hex, 6);

            ha = null;

            return lsResult;
        }

        #endregion

        #region  IPasswordEncryptionMethod 

        public string Encode(string username, string anOrgPin, string aNewPassword, Guid aUserGUID, string aSalt)
        {
            return GetUberMonet(anOrgPin);
        }

        #endregion

    }

}