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

namespace StellaOps.Feedser.Source.Distro.Ubuntu;

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

internal sealed class UbuntuFetchJob : IJob
{
    private readonly UbuntuConnector _connector;

    public UbuntuFetchJob(UbuntuConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class UbuntuParseJob : IJob
{
    private readonly UbuntuConnector _connector;

    public UbuntuParseJob(UbuntuConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class UbuntuMapJob : IJob
{
    private readonly UbuntuConnector _connector;

    public UbuntuMapJob(UbuntuConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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