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

namespace StellaOps.Feedser.Source.Vndr.Vmware;

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

internal sealed class VmwareFetchJob : IJob
{
    private readonly VmwareConnector _connector;

    public VmwareFetchJob(VmwareConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class VmwareParseJob : IJob
{
    private readonly VmwareConnector _connector;

    public VmwareParseJob(VmwareConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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

internal sealed class VmwareMapJob : IJob
{
    private readonly VmwareConnector _connector;

    public VmwareMapJob(VmwareConnector connector)
        => _connector = connector ?? throw new ArgumentNullException(nameof(connector));

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