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

namespace StellaOps.Feedser.Source.CertFr;

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

internal sealed class CertFrFetchJob : IJob
{
    private readonly CertFrConnector _connector;

    public CertFrFetchJob(CertFrConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CertFrParseJob : IJob
{
    private readonly CertFrConnector _connector;

    public CertFrParseJob(CertFrConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CertFrMapJob : IJob
{
    private readonly CertFrConnector _connector;

    public CertFrMapJob(CertFrConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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