namespace Tiku.Application.Security;

public static class BackendPermissions
{
    public const string TenantDashboardView = "tenant:dashboard:view";
    public const string TenantStaffManage = "tenant:staff:manage";
    public const string TenantRoleManage = "tenant:role:manage";
    public const string TenantStudentManage = "tenant:student:manage";
    public const string TenantContentManage = "tenant:question-bank:manage";
    public const string TenantVocabularyManage = "tenant:vocabulary:manage";
    public const string TenantHandbookManage = "tenant:handbook:manage";
    public const string TenantVideoManage = "tenant:video:manage";
    public const string TenantScorelineManage = "tenant:scoreline:manage";
    public const string TenantSiteContentManage = "tenant:site-content:manage";
    public const string TenantSettingsManage = "tenant:settings:manage";
    public const string TenantProviderManage = "tenant:provider:manage";
    public const string TenantCommerceOperate = "tenant:commerce:operate";
    public const string TenantCrmManage = "tenant:crm:manage";
    public const string TenantCommissionManage = "tenant:commission:manage";
    public const string TenantJobManage = "tenant:job:manage";
    public const string TenantBillingManage = "tenant:billing:manage";

    public const string PlatformDashboardView = "platform:dashboard:view";
    public const string PlatformTenantManage = "platform:tenant:manage";
    public const string PlatformStaffManage = "platform:staff:manage";
    public const string PlatformRoleManage = "platform:role:manage";
    public const string PlatformQuestionBankManage = "platform:question-bank:manage";
    public const string PlatformAuditView = "platform:audit:view";
    public const string PlatformBillingNotification = "platform:billing:notification";
    public const string PlatformSaasCatalogManage = "platform:saas-catalog:manage";
    public const string PlatformSaasBillingManage = "platform:saas-billing:manage";
    public const string PlatformCrmRead = "platform:crm:read";
    public const string PlatformCrmWrite = "platform:crm:write";
    public const string PlatformSmsRead = "platform:sms:read";
    public const string PlatformSmsWrite = "platform:sms:write";
    public const string PlatformPaymentRead = "platform:payment:read";
    public const string PlatformPaymentWrite = "platform:payment:write";

    public static readonly IReadOnlySet<string> Tenant = new HashSet<string>(StringComparer.Ordinal)
    {
        TenantDashboardView,
        TenantStaffManage,
        TenantRoleManage,
        TenantStudentManage,
        TenantContentManage,
        TenantVocabularyManage,
        TenantHandbookManage,
        TenantVideoManage,
        TenantScorelineManage,
        TenantSiteContentManage,
        TenantSettingsManage,
        TenantProviderManage,
        TenantCommerceOperate,
        TenantCrmManage,
        TenantCommissionManage,
        TenantJobManage,
        TenantBillingManage
    };

    public static readonly IReadOnlySet<string> Platform = new HashSet<string>(StringComparer.Ordinal)
    {
        PlatformDashboardView,
        PlatformTenantManage,
        PlatformStaffManage,
        PlatformRoleManage,
        PlatformQuestionBankManage,
        PlatformAuditView,
        PlatformBillingNotification,
        PlatformSaasCatalogManage,
        PlatformSaasBillingManage,
        PlatformCrmRead,
        PlatformCrmWrite,
        PlatformSmsRead,
        PlatformSmsWrite,
        PlatformPaymentRead,
        PlatformPaymentWrite
    };

    public static void EnsureTenant(string permissionCode)
    {
        if (!Tenant.Contains(permissionCode))
        {
            throw new ArgumentOutOfRangeException(nameof(permissionCode), permissionCode, "Unknown tenant permission.");
        }
    }

    public static void EnsurePlatform(string permissionCode)
    {
        if (!Platform.Contains(permissionCode))
        {
            throw new ArgumentOutOfRangeException(nameof(permissionCode), permissionCode, "Unknown platform permission.");
        }
    }
}
