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

namespace StellaOps.Feedser.Source.Ics.Cisa;

internal static class IcsCisaJobKinds
{
    public const string Fetch = "source:ics-cisa:fetch";
    public const string Parse = "source:ics-cisa:parse";
    public const string Map = "source:ics-cisa:map";
}

internal sealed class IcsCisaFetchJob : IJob
{
    private readonly IcsCisaConnector _connector;

    public IcsCisaFetchJob(IcsCisaConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class IcsCisaParseJob : IJob
{
    private readonly IcsCisaConnector _connector;

    public IcsCisaParseJob(IcsCisaConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class IcsCisaMapJob : IJob
{
    private readonly IcsCisaConnector _connector;

    public IcsCisaMapJob(IcsCisaConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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