using Backend.Common;

namespace Backend.Endpoints;

public static partial class AuthEndpoints
{
    public static IEndpointRouteBuilder MapAuthEndpoints(this IEndpointRouteBuilder app)
    {
        var group = app.MapGroup("/api/auth");

        group.MapPost("/dev-login", DevLogin)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("DevLogin")
            .WithOpenApi();

        group.MapPost("/demo-login", DemoLogin)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("DemoLogin")
            .WithOpenApi();

        group.MapPost("/team-login", TeamLogin)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("TeamLogin")
            .WithOpenApi();

        group.MapPost("/password/change", ChangePassword)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("ChangePassword")
            .WithOpenApi();

        group.MapPost("/twitch/authorize", StartTwitchAuthorization)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("StartTwitchAuthorization")
            .WithOpenApi();

        group.MapDelete("/twitch/binding", DisconnectTwitchBinding)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("DisconnectTwitchBinding")
            .WithOpenApi();

        group.MapGet("/twitch/callback", CompleteTwitchAuthorization)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("CompleteTwitchAuthorization")
            .WithOpenApi();

        group.MapGet("/session", GetSession)
            .WithName("GetSession")
            .WithOpenApi();

        group.MapPost("/logout", Logout)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("Logout")
            .WithOpenApi();

        group.MapDelete("/me/data", DeleteMyParticipationData)
            .RequireRateLimiting(ApplicationDefaults.AuthRateLimitPolicy)
            .WithName("DeleteMyParticipationData")
            .WithOpenApi();

        return app;
    }
}
