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

namespace StellaOps.Feedser.Source.Osv;

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

internal sealed class OsvFetchJob : IJob
{
    private readonly OsvConnector _connector;

    public OsvFetchJob(OsvConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class OsvParseJob : IJob
{
    private readonly OsvConnector _connector;

    public OsvParseJob(OsvConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class OsvMapJob : IJob
{
    private readonly OsvConnector _connector;

    public OsvMapJob(OsvConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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