Option Strict On
Option Explicit On

Imports System

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Friend-only host-adoption proof snapshot. It proves that an application host
    ''' can consume a control-owned boundary snapshot and layout/interaction state
    ''' without moving router, PageHost, native shell, public adapter, persistence, or
    ''' announcement ownership into the control.
    ''' </summary>
    Friend NotInheritable Class MASRouteShellHostAdoptionSnapshot
        Friend Sub New(version As Integer,
                       ownerKey As String,
                       evidenceKey As String,
                       boundaryKind As MASRouteShellBoundaryKind,
                       hostConsumesBoundarySnapshot As Boolean,
                       hasLayoutSnapshot As Boolean,
                       hasHostedContentSnapshot As Boolean,
                       hasInteractionSnapshot As Boolean,
                       keepsRouterExternal As Boolean,
                       keepsPageHostExternal As Boolean,
                       keepsNativeShellExternal As Boolean,
                       keepsPublicAdapterExternal As Boolean,
                       capturesPersistenceIntent As Boolean,
                       capturesFocusIntent As Boolean,
                       capturesAnnouncementIntent As Boolean,
                       capturesResponsiveIntent As Boolean,
                       note As String)
            Me.Version = Math.Max(1, version)
            Me.OwnerKey = Normalize(ownerKey)
            Me.EvidenceKey = Normalize(evidenceKey)
            Me.BoundaryKind = boundaryKind
            Me.HostConsumesBoundarySnapshot = hostConsumesBoundarySnapshot
            Me.HasLayoutSnapshot = hasLayoutSnapshot
            Me.HasHostedContentSnapshot = hasHostedContentSnapshot
            Me.HasInteractionSnapshot = hasInteractionSnapshot
            Me.KeepsRouterExternal = keepsRouterExternal
            Me.KeepsPageHostExternal = keepsPageHostExternal
            Me.KeepsNativeShellExternal = keepsNativeShellExternal
            Me.KeepsPublicAdapterExternal = keepsPublicAdapterExternal
            Me.CapturesPersistenceIntent = capturesPersistenceIntent
            Me.CapturesFocusIntent = capturesFocusIntent
            Me.CapturesAnnouncementIntent = capturesAnnouncementIntent
            Me.CapturesResponsiveIntent = capturesResponsiveIntent
            Me.Note = Normalize(note)
        End Sub

        Friend ReadOnly Property Version As Integer
        Friend ReadOnly Property OwnerKey As String
        Friend ReadOnly Property EvidenceKey As String
        Friend ReadOnly Property BoundaryKind As MASRouteShellBoundaryKind
        Friend ReadOnly Property HostConsumesBoundarySnapshot As Boolean
        Friend ReadOnly Property HasLayoutSnapshot As Boolean
        Friend ReadOnly Property HasHostedContentSnapshot As Boolean
        Friend ReadOnly Property HasInteractionSnapshot As Boolean
        Friend ReadOnly Property KeepsRouterExternal As Boolean
        Friend ReadOnly Property KeepsPageHostExternal As Boolean
        Friend ReadOnly Property KeepsNativeShellExternal As Boolean
        Friend ReadOnly Property KeepsPublicAdapterExternal As Boolean
        Friend ReadOnly Property CapturesPersistenceIntent As Boolean
        Friend ReadOnly Property CapturesFocusIntent As Boolean
        Friend ReadOnly Property CapturesAnnouncementIntent As Boolean
        Friend ReadOnly Property CapturesResponsiveIntent As Boolean
        Friend ReadOnly Property Note As String

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

        Friend ReadOnly Property HasHostIntent As Boolean
            Get
                Return CapturesPersistenceIntent AndAlso
                       (CapturesResponsiveIntent OrElse CapturesFocusIntent OrElse CapturesAnnouncementIntent)
            End Get
        End Property

        Friend ReadOnly Property IsSafeHostAdoptionProof As Boolean
            Get
                Return IsStructurallyValid AndAlso
                       HostConsumesBoundarySnapshot AndAlso
                       HasLayoutSnapshot AndAlso
                       HasHostedContentSnapshot AndAlso
                       HasHostIntent AndAlso
                       KeepsRouterExternal AndAlso
                       KeepsPageHostExternal AndAlso
                       KeepsNativeShellExternal AndAlso
                       KeepsPublicAdapterExternal
            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
