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

namespace StellaOps.Feedser.Source.Vndr.Apple;

internal static class AppleJobKinds
{
    public const string Fetch = "source:vndr-apple:fetch";
    public const string Parse = "source:vndr-apple:parse";
    public const string Map = "source:vndr-apple:map";
}

internal sealed class AppleFetchJob : IJob
{
    private readonly AppleConnector _connector;

    public AppleFetchJob(AppleConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class AppleParseJob : IJob
{
    private readonly AppleConnector _connector;

    public AppleParseJob(AppleConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class AppleMapJob : IJob
{
    private readonly AppleConnector _connector;

    public AppleMapJob(AppleConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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