namespace ZB.MOM.WW.ScadaBridge.Commons.Types.Transport;

// Warning is a NON-blocking advisory finding (appended after Blocker so the
// enum ordinal of the existing members is unchanged). Import may proceed with
// Warning items present; only Blocker items stop an apply. Template-script
// name-resolution findings surface as Warning because the design-time deploy
// gate (ScriptCompiler.TryCompile) re-validates them authoritatively; ApiMethod
// findings — which have no downstream gate — stay Blocker.
public enum ConflictKind { Identical, Modified, New, Blocker, Warning }

public sealed record ImportPreviewItem(
    string EntityType,
    string Name,
    int? ExistingVersion,
    int? IncomingVersion,
    ConflictKind Kind,
    string? FieldDiffJson,
    string? BlockerReason);

/// <summary>
/// A site reference in an incoming bundle that the operator must resolve before import.
/// <paramref name="AutoMatchTargetIdentifier"/> is the destination site the
/// importer auto-matched by identifier, or null when no match was found.
/// </summary>
public sealed record RequiredSiteMapping(
    string SourceSiteIdentifier,
    string SourceSiteName,
    string? AutoMatchTargetIdentifier);

/// <summary>
/// A connection reference (scoped to a source site) in an incoming bundle that the
/// operator must resolve before import. <paramref name="AutoMatchTargetName"/>
/// is the destination connection the importer auto-matched by name, or null when no
/// match was found.
/// </summary>
public sealed record RequiredConnectionMapping(
    string SourceSiteIdentifier,
    string SourceConnectionName,
    string? AutoMatchTargetName);

public sealed record ImportPreview(
    Guid SessionId,
    IReadOnlyList<ImportPreviewItem> Items,
    // Additive: site/connection references the operator must resolve before
    // applying. Defaulted to empty so every existing positional caller keeps compiling.
    IReadOnlyList<RequiredSiteMapping>? RequiredSiteMappings = null,
    IReadOnlyList<RequiredConnectionMapping>? RequiredConnectionMappings = null)
{
    /// <summary>Site references the operator must resolve before import. Never null.</summary>
    public IReadOnlyList<RequiredSiteMapping> RequiredSiteMappings { get; init; } =
        RequiredSiteMappings ?? Array.Empty<RequiredSiteMapping>();

    /// <summary>Connection references the operator must resolve before import. Never null.</summary>
    public IReadOnlyList<RequiredConnectionMapping> RequiredConnectionMappings { get; init; } =
        RequiredConnectionMappings ?? Array.Empty<RequiredConnectionMapping>();
}
