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

namespace StellaOps.Feedser.Source.Jvn;

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

internal sealed class JvnFetchJob : IJob
{
    private readonly JvnConnector _connector;

    public JvnFetchJob(JvnConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class JvnParseJob : IJob
{
    private readonly JvnConnector _connector;

    public JvnParseJob(JvnConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class JvnMapJob : IJob
{
    private readonly JvnConnector _connector;

    public JvnMapJob(JvnConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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