namespace MerchantService.Domain.AggregatesModel.MerchantStaffAggregate;

/// <summary>
/// EN: Maps permission claim strings (from IAM role_claims) to StaffPermissions bitmask.
/// VI: Map chuỗi permission claim (từ IAM role_claims) sang StaffPermissions bitmask.
/// </summary>
public static class PermissionConstants
{
    public const string ClaimType = "permission";

    private static readonly Dictionary<string, StaffPermissions> Map = new(StringComparer.OrdinalIgnoreCase)
    {
        ["ViewSales"] = StaffPermissions.ViewSales,
        ["ProcessPayment"] = StaffPermissions.ProcessPayment,
        ["RefundOrder"] = StaffPermissions.RefundOrder,
        ["ManageInventory"] = StaffPermissions.ManageInventory,
        ["ViewReports"] = StaffPermissions.ViewReports,
        ["ManageStaff"] = StaffPermissions.ManageStaff,
        ["ManageSettings"] = StaffPermissions.ManageSettings,
        ["All"] = StaffPermissions.All,
    };

    /// <summary>
    /// EN: Convert JWT permission claim values to StaffPermissions bitmask.
    /// VI: Chuyển đổi giá trị permission claim từ JWT sang StaffPermissions bitmask.
    /// </summary>
    public static StaffPermissions FromClaims(IEnumerable<string> claimValues)
    {
        var result = StaffPermissions.None;
        foreach (var val in claimValues)
        {
            if (Map.TryGetValue(val, out var perm))
                result |= perm;
        }
        return result;
    }
}
