Option Strict On
Option Explicit On

Namespace Nexamas.UI.Components

    Friend NotInheritable Class MASRouteShellHostAdoptionSamplePolicy
        Private Sub New()
        End Sub

        Friend Shared Function CreateAppLayoutSample(boundary As MASRouteShellBoundarySnapshot,
                                                     adoption As MASRouteShellHostAdoptionSnapshot,
                                                     layoutSnapshot As MASAppLayoutSnapshot,
                                                     hostedSnapshot As MASHostedContentContractSnapshot,
                                                     compactScenarioVerified As Boolean,
                                                     wideScenarioVerified As Boolean) As MASRouteShellHostAdoptionSampleSnapshot
            Return New MASRouteShellHostAdoptionSampleSnapshot(
                1,
                "applayout",
                "AppLayout.RealHostAdoptionSample",
                "AppLayout host adoption sample",
                MASRouteShellBoundaryKind.AppLayoutRouteOwnership,
                If(compactScenarioVerified, 1, 0) + If(wideScenarioVerified, 1, 0),
                boundary IsNot Nothing AndAlso MASRouteShellBoundaryPolicy.IsSafeClosedBoundary(boundary, "applayout", "AppLayout.RoutingOwnership", MASRouteShellBoundaryKind.AppLayoutRouteOwnership),
                MASRouteShellHostAdoptionPolicy.IsSafeHostAdoption(adoption, "applayout", "AppLayout.ResponsiveShellAdoption", MASRouteShellBoundaryKind.AppLayoutRouteOwnership),
                hostedSnapshot IsNot Nothing AndAlso hostedSnapshot.IsStructurallyValid AndAlso hostedSnapshot.HostedSlotCount > 0,
                layoutSnapshot IsNot Nothing AndAlso layoutSnapshot.Version > 0,
                checksResponsiveBreakpoints:=compactScenarioVerified AndAlso wideScenarioVerified,
                checksFocusHandoff:=False,
                checksAnnouncementIntent:=False,
                checksPersistenceIntent:=True,
                hasReleaseSampleDocumentation:=True,
                keepsRouterExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsRouter,
                keepsPageHostExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsPageHost,
                keepsNativeShellExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsNativeShell,
                keepsPublicAdapterExternal:=boundary IsNot Nothing AndAlso Not boundary.ExposesPublicAdapter,
                note:="Sample-level host adoption consumes AppLayout boundary/layout/hosted-slot snapshots across compact and wide scenarios while the host owns routing and PageHost decisions.")
        End Function

        Friend Shared Function CreateSplitViewSample(boundary As MASRouteShellBoundarySnapshot,
                                                     adoption As MASRouteShellHostAdoptionSnapshot,
                                                     layoutSnapshot As MASSplitViewLayoutSnapshot,
                                                     hostedSnapshot As MASHostedContentContractSnapshot,
                                                     splitterSnapshot As MASSplitViewKeyboardSplitterSnapshot,
                                                     focusScenarioVerified As Boolean,
                                                     announcementScenarioVerified As Boolean) As MASRouteShellHostAdoptionSampleSnapshot
            Return New MASRouteShellHostAdoptionSampleSnapshot(
                1,
                "splitview",
                "SplitView.RealHostAdoptionSample",
                "SplitView host adoption sample",
                MASRouteShellBoundaryKind.SplitViewShellIntegrationBoundary,
                If(focusScenarioVerified, 1, 0) + If(announcementScenarioVerified, 1, 0),
                boundary IsNot Nothing AndAlso MASRouteShellBoundaryPolicy.IsSafeClosedBoundary(boundary, "splitview", "SplitView.ShellIntegration", MASRouteShellBoundaryKind.SplitViewShellIntegrationBoundary),
                MASRouteShellHostAdoptionPolicy.IsSafeHostAdoption(adoption, "splitview", "SplitView.HostAdoptionProof", MASRouteShellBoundaryKind.SplitViewShellIntegrationBoundary),
                hostedSnapshot IsNot Nothing AndAlso hostedSnapshot.IsStructurallyValid AndAlso hostedSnapshot.HostedSlotCount > 0,
                layoutSnapshot IsNot Nothing AndAlso layoutSnapshot.Version > 0,
                checksResponsiveBreakpoints:=False,
                checksFocusHandoff:=focusScenarioVerified AndAlso splitterSnapshot IsNot Nothing AndAlso splitterSnapshot.HasKeyboardSplitterContract,
                checksAnnouncementIntent:=announcementScenarioVerified,
                checksPersistenceIntent:=True,
                hasReleaseSampleDocumentation:=True,
                keepsRouterExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsRouter,
                keepsPageHostExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsPageHost,
                keepsNativeShellExternal:=boundary IsNot Nothing AndAlso Not boundary.OwnsNativeShell,
                keepsPublicAdapterExternal:=boundary IsNot Nothing AndAlso Not boundary.ExposesPublicAdapter,
                note:="Sample-level host adoption consumes SplitView boundary/layout/hosted-pane/splitter snapshots for focus handoff and announcement intent while the host owns native shell integration.")
        End Function

        Friend Shared Function IsSafeRealHostAdoptionSample(snapshot As MASRouteShellHostAdoptionSampleSnapshot,
                                                           expectedOwner As String,
                                                           expectedEvidence As String,
                                                           expectedKind As MASRouteShellBoundaryKind) As Boolean
            If snapshot Is Nothing OrElse Not snapshot.IsSafeRealHostAdoptionSample Then Return False
            Return System.String.Equals(snapshot.OwnerKey, If(expectedOwner, System.String.Empty).Trim(), System.StringComparison.OrdinalIgnoreCase) AndAlso
                   System.String.Equals(snapshot.EvidenceKey, If(expectedEvidence, System.String.Empty).Trim(), System.StringComparison.OrdinalIgnoreCase) AndAlso
                   snapshot.BoundaryKind = expectedKind
        End Function
    End Class

End Namespace
