using System.Text.Json;
using Tiku.Application.Jobs;
using Tiku.Application.Tenancy;

namespace Tiku.Infrastructure.Tenancy;

internal sealed class TenantDomainRecheckJobHandler(ITenantDomainLifecycleService lifecycleService)
    : IBackgroundJobHandler
{
    public string JobType => "tenant_domain_recheck";

    public async Task<BackgroundJobHandlerResult> HandleAsync(
        BackgroundJobExecutionContext context,
        CancellationToken cancellationToken = default)
    {
        var processed = await lifecycleService.ProcessPendingAsync(cancellationToken);
        return new BackgroundJobHandlerResult(JsonSerializer.SerializeToElement(new { processed }));
    }
}
