using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.DependencyInjection;
using NetworkResurrector.Api.Authorization.Constants;
using NetworkResurrector.Api.Authorization.Handlers;
using NetworkResurrector.Api.Authorization.Requirements;

namespace NetworkResurrector.Api.Authorization
{
    public static class DependencyInjectionExtensions
    {
        public static void AddLocalAuthorization(this IServiceCollection services)
        {
            services.AddAuthorization(options =>
            {
                options.AddPolicy(Policies.OperateMachines, policy =>
                {
                    policy.Requirements.Add(new OperateMachinesRequirement());
                });
                options.AddPolicy(Policies.ViewMachines, policy =>
                {
                    policy.Requirements.Add(new ViewMachinesRequirement());
                });
                options.AddPolicy(Policies.SystemAdministration, policy =>
                {
                    policy.Requirements.Add(new SystemAdministrationRequirement());
                });
            });

            services.AddScoped<IAuthorizationHandler, PermissionsBasedAuthorizationHandler>();
        }
    }
}
