using OTSSignsOrchestrator.Server.Data.Entities;

namespace OTSSignsOrchestrator.Server.Workers;

/// <summary>
/// Common interface for all provisioning pipelines (Phase1, Phase2, etc.).
/// Resolved from DI via <see cref="IEnumerable{IProvisioningPipeline}"/> and matched by
/// <see cref="HandlesJobType"/>.
/// </summary>
public interface IProvisioningPipeline
{
    /// <summary>The <see cref="Job.JobType"/> this pipeline handles (e.g. "provision", "bootstrap").</summary>
    string HandlesJobType { get; }

    /// <summary>Execute the pipeline steps for the given job.</summary>
    Task ExecuteAsync(Job job, CancellationToken ct);
}

/// <summary>
/// Shared context extracted from <see cref="Job.Parameters"/> JSON and the associated
/// <see cref="Customer"/> / <see cref="Instance"/> entities. Passed between pipeline steps.
/// </summary>
public sealed record PipelineContext
{
    public required Guid JobId { get; init; }
    public required Guid CustomerId { get; init; }
    public required Guid InstanceId { get; init; }
    public required string Abbreviation { get; init; }
    public required string CompanyName { get; init; }
    public required string AdminEmail { get; init; }
    public required string AdminFirstName { get; init; }
    public required string InstanceUrl { get; init; }
    public required string DockerStackName { get; init; }

    /// <summary>Raw parameters JSON from the Job entity for step-specific overrides.</summary>
    public string? ParametersJson { get; init; }
}
