using FJPSite.Enums;
using Microsoft.AspNetCore.Authorization;

namespace FJPSite.Attributes;

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class HasPermissionAttribute : AuthorizeAttribute
{
    public FeatureEnum Feature { get; }
    public ActionEnum Action { get; }
    public HasPermissionAttribute(FeatureEnum feature, ActionEnum action)
    {
        Feature = feature;
        Action = action;
        Policy = BuildPolicyName(feature, action);
    }
    private static string BuildPolicyName(FeatureEnum feature, ActionEnum action)
    {
        return $"Permission.{feature}.{action}";
    }