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

namespace StellaOps.Feedser.Source.Distro.RedHat;

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

internal sealed class RedHatFetchJob : IJob
{
    private readonly RedHatConnector _connector;

    public RedHatFetchJob(RedHatConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class RedHatParseJob : IJob
{
    private readonly RedHatConnector _connector;

    public RedHatParseJob(RedHatConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class RedHatMapJob : IJob
{
    private readonly RedHatConnector _connector;

    public RedHatMapJob(RedHatConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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