using StellaOps.Feedser.Core.Jobs;

namespace StellaOps.Feedser.Source.Cve;

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

internal sealed class CveFetchJob : IJob
{
    private readonly CveConnector _connector;

    public CveFetchJob(CveConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CveParseJob : IJob
{
    private readonly CveConnector _connector;

    public CveParseJob(CveConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class CveMapJob : IJob
{
    private readonly CveConnector _connector;

    public CveMapJob(CveConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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