using Microsoft.AspNetCore.Identity;
using Tiku.Application.Auth;
using Tiku.Application.Security;
using Tiku.Application.Tenancy;
using Tiku.Domain.Identity;
using Tiku.Infrastructure.Persistence;
namespace Tiku.Infrastructure.Auth;

internal sealed record AuthServiceDependencies(
    IIdentityPersistence IdentityPersistence,
    ITenancyPersistence TenancyPersistence,
    IJobsOperationsPersistence JobsOperationsPersistence,
    SignInManager<User> SignInManager,
    UserManager<User> UserManager,
    ISmsVerificationService SmsVerificationService,
    IAuthSessionStore SessionStore,
    IWechatOAuthClient WechatOAuthClient,
    ITenantExternalProviderConfigService ProviderConfigService,
    IFeatureAccessService FeatureAccessService);

internal abstract partial class AuthServiceBase(AuthServiceDependencies dependencies)
{
    protected IIdentityPersistence identityPersistence { get; } = dependencies.IdentityPersistence;
    protected ITenancyPersistence tenancyPersistence { get; } = dependencies.TenancyPersistence;
    protected IJobsOperationsPersistence jobsOperationsPersistence { get; } = dependencies.JobsOperationsPersistence;
    protected SignInManager<User> signInManager { get; } = dependencies.SignInManager;
    protected UserManager<User> userManager { get; } = dependencies.UserManager;
    protected ISmsVerificationService smsVerificationService { get; } = dependencies.SmsVerificationService;
    protected IAuthSessionStore sessionStore { get; } = dependencies.SessionStore;
    protected IWechatOAuthClient wechatOAuthClient { get; } = dependencies.WechatOAuthClient;
    protected ITenantExternalProviderConfigService providerConfigService { get; } = dependencies.ProviderConfigService;
    protected IFeatureAccessService featureAccessService { get; } = dependencies.FeatureAccessService;
    protected const string PasswordProvider = "password";
    protected const string SmsProvider = "sms";
    protected const string WechatWebProvider = "wechat_web";
    protected const string WechatMiniAppProvider = "wechat_miniapp";
    protected static readonly string[] WechatWebProviderAliases = ["wechat_web", "wechat-web", "wechat"];

    protected static readonly string[] WechatMiniAppProviderAliases =
        ["wechat-miniapp", "wechat_miniapp", "wechat-mini", "wechatMiniapp"];

    protected static readonly string[] WechatIdentityProviders =
        ["wechat_web", "wechat-web", "wechat", "wechat-miniapp", "wechat_miniapp", "wechat-mini", "wechatMiniapp"];
}
