using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace StellaOps.Feedser.Core.Jobs;

public sealed class JobExecutionContext
{
    public JobExecutionContext(
        Guid runId,
        string kind,
        string trigger,
        IReadOnlyDictionary<string, object?> parameters,
        IServiceProvider services,
        TimeProvider timeProvider,
        ILogger logger)
    {
        RunId = runId;
        Kind = kind;
        Trigger = trigger;
        Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters));
        Services = services ?? throw new ArgumentNullException(nameof(services));
        TimeProvider = timeProvider ?? throw new ArgumentNullException(nameof(timeProvider));
        Logger = logger ?? throw new ArgumentNullException(nameof(logger));
    }

    public Guid RunId { get; }

    public string Kind { get; }

    public string Trigger { get; }

    public IReadOnlyDictionary<string, object?> Parameters { get; }

    public IServiceProvider Services { get; }

    public TimeProvider TimeProvider { get; }

    public ILogger Logger { get; }

    public T GetRequiredService<T>() where T : notnull
        => Services.GetRequiredService<T>();
}
