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

namespace StellaOps.Feedser.Source.CertIn;

internal static class CertInJobKinds
{
    public const string Fetch = "source:cert-in:fetch";
    public const string Parse = "source:cert-in:parse";
    public const string Map = "source:cert-in:map";
}

internal sealed class CertInFetchJob : IJob
{
    private readonly CertInConnector _connector;

    public CertInFetchJob(CertInConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CertInParseJob : IJob
{
    private readonly CertInConnector _connector;

    public CertInParseJob(CertInConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CertInMapJob : IJob
{
    private readonly CertInConnector _connector;

    public CertInMapJob(CertInConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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