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

namespace StellaOps.Feedser.Source.Distro.Debian;

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

internal sealed class DebianFetchJob : IJob
{
    private readonly DebianConnector _connector;

    public DebianFetchJob(DebianConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class DebianParseJob : IJob
{
    private readonly DebianConnector _connector;

    public DebianParseJob(DebianConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class DebianMapJob : IJob
{
    private readonly DebianConnector _connector;

    public DebianMapJob(DebianConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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