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

namespace StellaOps.Feedser.Source.Ics.Kaspersky;

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

internal sealed class KasperskyFetchJob : IJob
{
    private readonly KasperskyConnector _connector;

    public KasperskyFetchJob(KasperskyConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class KasperskyParseJob : IJob
{
    private readonly KasperskyConnector _connector;

    public KasperskyParseJob(KasperskyConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class KasperskyMapJob : IJob
{
    private readonly KasperskyConnector _connector;

    public KasperskyMapJob(KasperskyConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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