namespace Backend.Endpoints;

public static partial class AdminModerationEndpoints
{
    public static RouteGroupBuilder MapAdminModerationEndpoints(this RouteGroupBuilder group)
    {
        group.MapDelete("/clips/{clipId:int}", DeleteClip)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Clips))
            .WithName("DeleteAdminClip")
            .WithOpenApi();
        group.MapPost("/clips/{clipId:int}/status", UpdateClipStatus)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Clips))
            .WithName("UpdateAdminClipStatus")
            .WithOpenApi();
        group.MapPost("/nominations/{nominationId:int}/approve", ApproveNomination)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("ApproveAdminNomination")
            .WithOpenApi();
        group.MapPost("/nominations/{nominationId:int}/reject", RejectNomination)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("RejectAdminNomination")
            .WithOpenApi();
        group.MapPost("/nominations/{nominationId:int}/reopen", ReopenRejectedNomination)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("ReopenRejectedAdminNomination")
            .WithOpenApi();
        group.MapPost("/nominations/{nominationId:int}/tracking-review", UpdateNominationTrackingReview)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("UpdateNominationTrackingReview")
            .WithOpenApi();
        group.MapGet("/nominations/link-blacklist", GetNominationLinkBlacklist)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequirePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("GetAdminNominationLinkBlacklist")
            .WithOpenApi();
        group.MapPut("/nominations/link-blacklist", UpdateNominationLinkBlacklist)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("UpdateAdminNominationLinkBlacklist")
            .WithOpenApi();
        group.MapPost("/nominations/link-blacklist", AddNominationLinkBlacklistEntry)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Nominations))
            .WithName("AddAdminNominationLinkBlacklistEntry")
            .WithOpenApi();
        group.MapGet("/risk-flags", GetRiskFlags)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequirePermission(context, next, Backend.Security.AdminPermissionCatalog.Risk))
            .WithName("GetAdminRiskFlags")
            .WithOpenApi();
        group.MapPost("/risk-flags/{riskFlagId:int}/resolve", ResolveRiskFlag)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Risk))
            .WithName("ResolveRiskFlag")
            .WithOpenApi();
        group.MapPost("/risk-flags/bulk-resolve", BulkResolveRiskFlags)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Risk))
            .WithName("BulkResolveRiskFlags")
            .WithOpenApi();
        group.MapGet("/risk-rules", GetRiskRules)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequirePermission(context, next, Backend.Security.AdminPermissionCatalog.Risk))
            .WithName("GetAdminRiskRules")
            .WithOpenApi();
        group.MapPut("/risk-rules", UpdateRiskRules)
            .AddEndpointFilter((context, next) => AdminEndpointConventions.RequireWritePermission(context, next, Backend.Security.AdminPermissionCatalog.Risk))
            .WithName("UpdateAdminRiskRules")
            .WithOpenApi();
        return group;
    }
}
