using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Flattening;
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager;
///
/// Abstraction over the TemplateEngine flattening + validation + hashing pipeline.
/// Used by DeploymentService to obtain a validated, hashed FlattenedConfiguration.
///
public interface IFlatteningPipeline
{
///
/// Flattens and validates an instance configuration, returning the configuration,
/// revision hash, and validation result.
///
/// Id of the instance to flatten and validate.
/// Cancellation token.
///
/// When true (the deploy default), the authoritative Roslyn script-compilation
/// gate runs. When false, that compile step is skipped — used by the read-only
/// staleness/comparison paths (Deployments comparison page,
/// )
/// which need only the flattened config + revision hash, not a compile. Structural and
/// semantic validation still run in both cases.
///
///
/// Optional flatten session memoising template-chain, composition and
/// session-global repository reads. Pass one shared session when flattening
/// several instances in a batch (see DeploymentService.DeploySiteAsync)
/// so a template chain shared by N instances is walked once. When
/// the pipeline creates a private single-use session,
/// which still de-duplicates the repeated composed-chain loads inside one
/// instance's flatten. Additive parameter — existing callers are unaffected.
///
/// A task that resolves to the flattened configuration, revision hash, and validation result; or a failure result if flattening could not complete.
Task> FlattenAndValidateAsync(
int instanceId,
CancellationToken cancellationToken = default,
bool validateScripts = true,
FlattenSession? session = null);
///
/// Flattens as if an instance with no overrides and no
/// bindings existed at . Attribute list only — no validation,
/// no revision hash, nothing persisted. Used by the Create Instance page to show the
/// module groups before the instance row exists.
///
/// Id of the template to preview.
/// Id of the target site, whose data connections resolve references.
/// Cancellation token.
/// The flattened configuration of the hypothetical instance, or a failure result.
Task> PreviewAsync(
int templateId,
int siteId,
CancellationToken cancellationToken = default);
///
/// Creates a fresh bound to this pipeline's
/// watermark, for a caller that wants to share one across a batch of
/// calls.
///
/// A new, empty session.
FlattenSession CreateSession();
}
///
/// Result of the flattening pipeline: configuration, hash, and validation.
///
public record FlatteningPipelineResult(
FlattenedConfiguration Configuration,
string RevisionHash,
ValidationResult Validation);