using System.Security.Claims;
using Microsoft.AspNetCore.Authentication;

using static NPin.Framework.AspNetCore.Authentication.OAuth.Gitee.GiteeAuthenticationConstants;

namespace NPin.Framework.AspNetCore.Authentication.OAuth.Gitee;

public class GiteeAuthenticationOptions: AuthenticationOAuthOptions
{
    public GiteeAuthenticationOptions()
    {
        ClaimsIssuer = GiteeAuthenticationDefaults.Issuer;

        CallbackPath = GiteeAuthenticationDefaults.CallbackPath;

        AuthorizationEndpoint = GiteeAuthenticationDefaults.AuthorizationEndpoint;
        TokenEndpoint = GiteeAuthenticationDefaults.TokenEndpoint;
        UserInformationEndpoint = GiteeAuthenticationDefaults.UserInformationEndpoint;
        UserEmailsEndpoint = GiteeAuthenticationDefaults.UserEmailsEndpoint;

        Scope.Add("user_info");
        Scope.Add("emails");

        ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
        ClaimActions.MapJsonKey(ClaimTypes.Name, "login");
        ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
        ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
        ClaimActions.MapJsonKey(Claims.Url, "url");
    }

    /// <summary>
    /// Gets or sets the address of the endpoint exposing
    /// the email addresses associated with the logged in user.
    /// </summary>
    public string UserEmailsEndpoint { get; set; }
}