Option Strict On
Option Explicit On

Imports System

Namespace Nexamas.UI.Components

    ''' <summary>
    ''' Friend-only release-sample adoption snapshot. It proves that an actual host
    ''' sample can consume the boundary/adoption snapshots for AppLayout or SplitView
    ''' while keeping routing, native shell, PageHost, public adapters, and storage
    ''' outside the product control.
    ''' </summary>
    Friend NotInheritable Class MASRouteShellHostAdoptionSampleSnapshot
        Friend Sub New(version As Integer,
                       ownerKey As String,
                       evidenceKey As String,
                       sampleName As String,
                       boundaryKind As MASRouteShellBoundaryKind,
                       hostScenarioCount As Integer,
                       hasBoundarySnapshot As Boolean,
                       hasHostAdoptionSnapshot As Boolean,
                       hasHostedContentSnapshot As Boolean,
                       hasLayoutSnapshot As Boolean,
                       checksResponsiveBreakpoints As Boolean,
                       checksFocusHandoff As Boolean,
                       checksAnnouncementIntent As Boolean,
                       checksPersistenceIntent As Boolean,
                       hasReleaseSampleDocumentation As Boolean,
                       keepsRouterExternal As Boolean,
                       keepsPageHostExternal As Boolean,
                       keepsNativeShellExternal As Boolean,
                       keepsPublicAdapterExternal As Boolean,
                       note As String)
            Me.Version = Math.Max(1, version)
            Me.OwnerKey = Normalize(ownerKey)
            Me.EvidenceKey = Normalize(evidenceKey)
            Me.SampleName = Normalize(sampleName)
            Me.BoundaryKind = boundaryKind
            Me.HostScenarioCount = Math.Max(0, hostScenarioCount)
            Me.HasBoundarySnapshot = hasBoundarySnapshot
            Me.HasHostAdoptionSnapshot = hasHostAdoptionSnapshot
            Me.HasHostedContentSnapshot = hasHostedContentSnapshot
            Me.HasLayoutSnapshot = hasLayoutSnapshot
            Me.ChecksResponsiveBreakpoints = checksResponsiveBreakpoints
            Me.ChecksFocusHandoff = checksFocusHandoff
            Me.ChecksAnnouncementIntent = checksAnnouncementIntent
            Me.ChecksPersistenceIntent = checksPersistenceIntent
            Me.HasReleaseSampleDocumentation = hasReleaseSampleDocumentation
            Me.KeepsRouterExternal = keepsRouterExternal
            Me.KeepsPageHostExternal = keepsPageHostExternal
            Me.KeepsNativeShellExternal = keepsNativeShellExternal
            Me.KeepsPublicAdapterExternal = keepsPublicAdapterExternal
            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 SampleName As String
        Friend ReadOnly Property BoundaryKind As MASRouteShellBoundaryKind
        Friend ReadOnly Property HostScenarioCount As Integer
        Friend ReadOnly Property HasBoundarySnapshot As Boolean
        Friend ReadOnly Property HasHostAdoptionSnapshot As Boolean
        Friend ReadOnly Property HasHostedContentSnapshot As Boolean
        Friend ReadOnly Property HasLayoutSnapshot As Boolean
        Friend ReadOnly Property ChecksResponsiveBreakpoints As Boolean
        Friend ReadOnly Property ChecksFocusHandoff As Boolean
        Friend ReadOnly Property ChecksAnnouncementIntent As Boolean
        Friend ReadOnly Property ChecksPersistenceIntent As Boolean
        Friend ReadOnly Property HasReleaseSampleDocumentation 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 Note As String

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

        Friend ReadOnly Property IsSafeRealHostAdoptionSample As Boolean
            Get
                Return IsStructurallyValid AndAlso
                       HostScenarioCount >= 2 AndAlso
                       HasBoundarySnapshot AndAlso
                       HasHostAdoptionSnapshot AndAlso
                       HasHostedContentSnapshot AndAlso
                       HasLayoutSnapshot AndAlso
                       ChecksPersistenceIntent AndAlso
                       HasReleaseSampleDocumentation AndAlso
                       KeepsRouterExternal AndAlso
                       KeepsPageHostExternal AndAlso
                       KeepsNativeShellExternal AndAlso
                       KeepsPublicAdapterExternal AndAlso
                       (ChecksResponsiveBreakpoints OrElse ChecksFocusHandoff OrElse ChecksAnnouncementIntent)
            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
