using Innoactive.AccessControl.OAuth2;
using Innoactive.Portal.AccessControl.Launcher;
using System;
using UnityEngine;

namespace Innoactive.AccessControl.Authorizer
{
    public class WindowsAuthorizer : IAuthorizer
    {
        public bool Authorize(OAuth2ClientSettings clientSettings)
        {
            if (string.IsNullOrEmpty(clientSettings.clientId))
            {
                Debug.LogError("No clientId provided. Cannot proceed with Authorization");
                return false;
            }

            try
            {
                if (AccessControlIntegrity.CheckAccessControlLibraryIntegrity() == false)
                {
                    return false;
                }

                IAccessControl launcherAuthorization = new LauncherAccessControl();
                bool isAuthorized = launcherAuthorization.AuthorizeApplication(clientSettings.clientId);

                return isAuthorized;
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
                return false;
            }
        }
    }
}
