using DataProviders.Collections;
using DomainObjects.Documents;
using Microsoft.AspNetCore.Authorization;
using WeatherForecast.Policies.Abstractions;
using WeatherForecast.Services;

namespace WeatherForecast.Policies {

  /// <summary>
  /// 
  /// </summary>
  public class ShopCartAuthorizationHandler : AuthorizationHandlerBase<ShopCartAuthorizationRequirement, List<ShopCartDocument>> {

    /// <summary>
    /// 
    /// </summary>
    /// <param name="contextAccessor"></param>
    /// <param name="userDataProvider"></param>
    /// <param name="accountService"></param>
    public ShopCartAuthorizationHandler(
      IHttpContextAccessor contextAccessor,
      IUserDataProvider userDataProvider,
      IAccountPolicyService accountService
    ) : base(contextAccessor, userDataProvider, accountService) { }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="context"></param>
    /// <param name="requirement"></param>
    /// <param name="resource"></param>
    /// <returns></returns>
    protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, ShopCartAuthorizationRequirement requirement, List<ShopCartDocument> resource) {
      var user = GetUser(context);
      if (user == null)
        return Task.CompletedTask;

      // any authenticated user except 

      context.Succeed(requirement);

      return Task.CompletedTask;
    }
  }

  /// <summary>
  /// 
  /// </summary>
  public class ShopCartAuthorizationRequirement : AuthorizationRequirementBase { }
}
