Option Strict On
Option Explicit On

Imports System

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Friend-only snapshot that proves a control's route/shell boundary is explicit.
    ''' The snapshot is intentionally descriptive: it records what the control does
    ''' not own, and whether it exposes enough host-facing state for a higher-level
    ''' application shell to coordinate routing, focus, persistence, or announcements
    ''' without moving that ownership into the control.
    ''' </summary>
    Friend NotInheritable Class MASRouteShellBoundarySnapshot
        Friend Sub New(version As Integer,
                       ownerKey As String,
                       kind As MASRouteShellBoundaryKind,
                       evidenceKey As String,
                       ownsRouter As Boolean,
                       ownsPageHost As Boolean,
                       ownsNativeShell As Boolean,
                       exposesPublicAdapter As Boolean,
                       observesExternalRoute As Boolean,
                       providesHostBoundarySnapshot As Boolean,
                       boundaryNote As String)
            Me.Version = Math.Max(1, version)
            Me.OwnerKey = Normalize(ownerKey)
            Me.Kind = kind
            Me.EvidenceKey = Normalize(evidenceKey)
            Me.OwnsRouter = ownsRouter
            Me.OwnsPageHost = ownsPageHost
            Me.OwnsNativeShell = ownsNativeShell
            Me.ExposesPublicAdapter = exposesPublicAdapter
            Me.ObservesExternalRoute = observesExternalRoute
            Me.ProvidesHostBoundarySnapshot = providesHostBoundarySnapshot
            Me.BoundaryNote = Normalize(boundaryNote)
        End Sub

        Friend ReadOnly Property Version As Integer
        Friend ReadOnly Property OwnerKey As String
        Friend ReadOnly Property Kind As MASRouteShellBoundaryKind
        Friend ReadOnly Property EvidenceKey As String
        Friend ReadOnly Property OwnsRouter As Boolean
        Friend ReadOnly Property OwnsPageHost As Boolean
        Friend ReadOnly Property OwnsNativeShell As Boolean
        Friend ReadOnly Property ExposesPublicAdapter As Boolean
        Friend ReadOnly Property ObservesExternalRoute As Boolean
        Friend ReadOnly Property ProvidesHostBoundarySnapshot As Boolean
        Friend ReadOnly Property BoundaryNote As String

        Friend ReadOnly Property IsStructurallyValid As Boolean
            Get
                Return Version > 0 AndAlso
                       OwnerKey.Length > 0 AndAlso
                       Kind <> MASRouteShellBoundaryKind.Unknown AndAlso
                       EvidenceKey.Length > 0 AndAlso
                       BoundaryNote.Length > 0
            End Get
        End Property

        Friend ReadOnly Property IsProductionSafeBoundary As Boolean
            Get
                Return IsStructurallyValid AndAlso
                       Not OwnsRouter AndAlso
                       Not OwnsPageHost AndAlso
                       Not OwnsNativeShell AndAlso
                       Not ExposesPublicAdapter AndAlso
                       ProvidesHostBoundarySnapshot
            End Get
        End Property

        Friend ReadOnly Property IsPureVisualBoundary As Boolean
            Get
                Return IsProductionSafeBoundary AndAlso Not ObservesExternalRoute
            End Get
        End Property

        Private Shared Function Normalize(value As String) As String
            If value Is Nothing Then Return String.Empty
            Dim text As String = value.Trim()
            Do While text.Contains("  ")
                text = text.Replace("  ", " ")
            Loop
            Return text
        End Function
    End Class

End Namespace
