using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;

namespace Website
{
  public class CustomClaimsFactory : UserClaimsPrincipalFactory<IdentityUser>
  {
    public CustomClaimsFactory(
      UserManager<IdentityUser> userManager,
      IOptions<IdentityOptions> optionsAccessor)
      : base(userManager, optionsAccessor)
    {
    }

    protected override async Task<ClaimsIdentity> GenerateClaimsAsync(IdentityUser user)
    {
      var identity = await base.GenerateClaimsAsync(user);

      if (await UserManager.IsInRoleAsync(user, "Administrator"))
      {
        identity.AddClaim(new Claim("Admin", "1"));
      }

      return identity;
    }
  }
}