using System;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Feedser.Core.Jobs;

namespace StellaOps.Feedser.Source.Kev;

internal static class KevJobKinds
{
    public const string Fetch = "source:kev:fetch";
    public const string Parse = "source:kev:parse";
    public const string Map = "source:kev:map";
}

internal sealed class KevFetchJob : IJob
{
    private readonly KevConnector _connector;

    public KevFetchJob(KevConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

    public Task ExecuteAsync(JobExecutionContext context, CancellationToken cancellationToken)
        => _connector.FetchAsync(context.Services, cancellationToken);
}

internal sealed class KevParseJob : IJob
{
    private readonly KevConnector _connector;

    public KevParseJob(KevConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

    public Task ExecuteAsync(JobExecutionContext context, CancellationToken cancellationToken)
        => _connector.ParseAsync(context.Services, cancellationToken);
}

internal sealed class KevMapJob : IJob
{
    private readonly KevConnector _connector;

    public KevMapJob(KevConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

    public Task ExecuteAsync(JobExecutionContext context, CancellationToken cancellationToken)
        => _connector.MapAsync(context.Services, cancellationToken);
}
