using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;

namespace ZB.MOM.WW.ScadaBridge.DeploymentManager;

/// <summary>
/// Abstraction over the TemplateEngine flattening + validation + hashing pipeline.
/// Used by DeploymentService to obtain a validated, hashed FlattenedConfiguration.
/// </summary>
public interface IFlatteningPipeline
{
    /// <summary>
    /// Flattens and validates an instance configuration, returning the configuration,
    /// revision hash, and validation result.
    /// </summary>
    /// <param name="instanceId">Id of the instance to flatten and validate.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    /// <returns>A task that resolves to the flattened configuration, revision hash, and validation result; or a failure result if flattening could not complete.</returns>
    Task<Result<FlatteningPipelineResult>> FlattenAndValidateAsync(
        int instanceId,
        CancellationToken cancellationToken = default);
}

/// <summary>
/// Result of the flattening pipeline: configuration, hash, and validation.
/// </summary>
public record FlatteningPipelineResult(
    FlattenedConfiguration Configuration,
    string RevisionHash,
    ValidationResult Validation);
