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

/// <summary>
/// How a source-environment site or connection referenced by an incoming bundle is
/// resolved against the destination environment during import.
/// </summary>
public enum MappingAction
{
    /// <summary>Bind the source name to an existing destination site/connection
    /// (the corresponding <c>Target*</c> identifier is required).</summary>
    MapToExisting,

    /// <summary>Create a new destination site/connection from the bundle's payload
    /// (the corresponding <c>Target*</c> identifier is left null).</summary>
    CreateNew,
}

/// <summary>
/// Resolves one site referenced by an incoming bundle (site/instance-scoped
/// transport). <paramref name="TargetSiteIdentifier"/> is required when
/// <paramref name="Action"/> is <see cref="MappingAction.MapToExisting"/> and null
/// when it is <see cref="MappingAction.CreateNew"/>.
/// </summary>
public sealed record SiteMapping(
    string SourceSiteIdentifier,
    MappingAction Action,
    string? TargetSiteIdentifier);

/// <summary>
/// Resolves one data connection (scoped to a source site) referenced by an incoming
/// bundle. <paramref name="TargetConnectionName"/> is required when
/// <paramref name="Action"/> is <see cref="MappingAction.MapToExisting"/> and null
/// when it is <see cref="MappingAction.CreateNew"/>.
/// </summary>
public sealed record ConnectionMapping(
    string SourceSiteIdentifier,
    string SourceConnectionName,
    MappingAction Action,
    string? TargetConnectionName);

/// <summary>
/// The operator-supplied resolution of every source-environment site and connection
/// name an incoming bundle references, applied during import. Crosses the Central UI ⇆
/// ManagementActor boundary via System.Text.Json.
/// </summary>
public sealed record BundleNameMap(
    IReadOnlyList<SiteMapping> Sites,
    IReadOnlyList<ConnectionMapping> Connections)
{
    /// <summary>An empty map (no site or connection mappings).</summary>
    public static BundleNameMap Empty { get; } =
        new(Array.Empty<SiteMapping>(), Array.Empty<ConnectionMapping>());
}
