using System;
using System.Text;

namespace Sockeye.Util
{

    public static class AutoOrderProcessingUtil
    {
        // static System.Text.Encoding ISO_8859_1_ENCODING = System.Text.Encoding.GetEncoding("ISO-8859-1");
        static Encoding ISO_8859_1_ENCODING = System.Text.Encoding.GetEncoding("ISO-8859-1");
        public static (string, string) GetUsernameAndPasswordFromAuthorizeHeader(string authorizeHeader)
        {
            if (authorizeHeader == null || !authorizeHeader.Contains("Basic "))
                return (null, null);

            string encodedUsernamePassword = authorizeHeader.Substring("Basic ".Length).Trim();
            string usernamePassword = ISO_8859_1_ENCODING.GetString(Convert.FromBase64String(encodedUsernamePassword));

            string username = usernamePassword.Split(':')[0];
            string password = usernamePassword.Split(':')[1];

            return (username, password);
        }

    }//eoc

}//eons