using FastEndpoints;
using TaxBaik.Web.Services;

namespace TaxBaik.Web.Endpoints.Admin;

/// <summary>
/// Sitemap 및 RSS 검증 엔드포인트 (관리자 전용)
/// </summary>
public class ValidateSitemapEndpoint : EndpointWithoutRequest
{
    private readonly SitemapValidationService _validationService;

    public ValidateSitemapEndpoint(SitemapValidationService validationService)
    {
        _validationService = validationService;
    }

    public override void Configure()
    {
        Get("/api/admin/validate/sitemap");
        Policies("AdminOnly");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var result = await _validationService.ValidateSitemapAsync();
        await SendOkAsync(result, cancellation: ct);
    }
}

public class ValidateRssEndpoint : EndpointWithoutRequest
{
    private readonly SitemapValidationService _validationService;

    public ValidateRssEndpoint(SitemapValidationService validationService)
    {
        _validationService = validationService;
    }

    public override void Configure()
    {
        Get("/api/admin/validate/rss");
        Policies("AdminOnly");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var result = await _validationService.ValidateRssFeedAsync();
        await SendOkAsync(result, cancellation: ct);
    }
}

public class ValidateConsistencyEndpoint : EndpointWithoutRequest
{
    private readonly SitemapValidationService _validationService;

    public ValidateConsistencyEndpoint(SitemapValidationService validationService)
    {
        _validationService = validationService;
    }

    public override void Configure()
    {
        Get("/api/admin/validate/consistency");
        Policies("AdminOnly");
    }

    public override async Task HandleAsync(CancellationToken ct)
    {
        var result = await _validationService.ValidateConsistencyAsync();
        await SendOkAsync(result, cancellation: ct);
    }
}
