using CloudBuilder.Core.DependencyInjection.Request;
using CloudBuilder.Core.Request;
using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/*
{
  "CloudBuilder": {
    "Culture": "zh-cn",
  }
}
*/

namespace CloudBuilder.Core.DependencyInjection.Request
{
    public class LoginContext : IContext
    {
        public const string CULTURE_EN = "en";
        private string culture = null!;
        private string token = null!;
        private dynamic permissionInfo = null!;
        private readonly IConfiguration configuration;

        public string DefaultVersion { get; set; }
        public string Requestor { get; set; }
        public string UserType { get; set; }
        public DateTime LoginDate { get; set; }
        public string DefaultCopyright { get; set; }

        public string DefaultTitle { get; set; }

        public LoginContext(IConfiguration configuration)
        {
            this.configuration = configuration;

            culture = this.configuration["CloudBuilder:Culture"]!;
            DefaultVersion = this.configuration["CloudBuilder:DefaultVersion"] ?? "Ver.0.0.0.1";
            Requestor = string.Empty;
            LoginDate = DateTime.Now;
            DefaultCopyright = this.configuration["CloudBuilder:DefaultCopyright"] ?? "版权所有 © 2025 有家相册";
        }

        public bool Assert(Func<string, bool> action, string permissionName)
        {
            return action(permissionName);
        }

        public bool Assert(Func<string, string, bool> action, string permissionName, string operate)
        {
            return action(permissionName, operate);
        }

        public bool Assert(Func<string, Operate, bool> action, string permissionName, Operate operate)
        {
            return action(permissionName, operate);
        }

        public bool AssertDependents(Func<string, string, bool> action, string permissionName, string dependents)
        {
            return action(permissionName, dependents);
        }

        public bool AssertDependents(Func<string, string, Operate, bool> action, string permissionName, string dependents, Operate operate)
        {
            return action(permissionName, dependents, operate);
        }

        public string GetCulture()
        {
            return this.culture;
        }

        public void SetCulture(string culture)
        {
            this.culture = culture;
        }

        public string GetToken()
        {
            return this.token;
        }

        public void SetToken(string token)
        {
            this.token = token;
        }

        public dynamic GetPermissionInfo()
        {
            return this.permissionInfo;
        }

        public void SetPermissionInfo(dynamic permissionInfo)
        {
            this.permissionInfo = permissionInfo;
        }
    }
}
