Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports Nexamas.UI.Components

Namespace Nexamas.UI.Quality

    ''' <summary>
    ''' Friend-only proof for Targeted Closure Phase 4. It closes the remaining
    ''' route/shell-boundary gaps for AppLayout, MasterDetailView, and SplitView
    ''' by proving that each control exposes explicit host-facing boundary evidence
    ''' without becoming a router, page host, public adapter, or native shell.
    ''' </summary>
    Friend NotInheritable Class MASRoutingShellBoundaryClosureGate

        Private Sub New()
        End Sub

        Friend Shared Function Passes() As Boolean
            Return EvaluateFindings().Count = 0
        End Function

        Friend Shared Function EvaluateFindings() As IReadOnlyList(Of MASCommercialReadinessFinding)
            Dim findings As New List(Of MASCommercialReadinessFinding)()
            ValidateAppLayout(findings)
            ValidateMasterDetailView(findings)
            ValidateSplitView(findings)
            Return findings
        End Function

        Private Shared Sub ValidateAppLayout(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASAppLayout = MASAppLayout.Create("Route boundary proof")
                If Not control.HasRouteOwnershipBoundaryForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("applayout", "AppLayout.RoutingOwnership", MASCommercialReadinessFindingSeverity.Error, "AppLayout route/page ownership boundary did not prove a safe visual-only host boundary."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASRoutingShellBoundaryClosureGate.AppLayout")
                findings.Add(New MASCommercialReadinessFinding("applayout", "AppLayout.RoutingOwnership", MASCommercialReadinessFindingSeverity.Error, "AppLayout route/page ownership boundary threw during validation."))
            End Try
        End Sub

        Private Shared Sub ValidateMasterDetailView(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASMasterDetailView = MASMasterDetailView.Create("Routing boundary proof")
                control.AddItem("case-1", "Case 1", "Boundary", "Detail", "Routing remains outside the control.")
                If Not control.HasRoutingPublicAdapterBoundaryForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("masterdetail", "MasterDetail.RoutingPublicAdapter", MASCommercialReadinessFindingSeverity.Error, "MasterDetailView routing/public-adapter boundary did not prove a safe visual/source-projection boundary."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASRoutingShellBoundaryClosureGate.MasterDetail")
                findings.Add(New MASCommercialReadinessFinding("masterdetail", "MasterDetail.RoutingPublicAdapter", MASCommercialReadinessFindingSeverity.Error, "MasterDetailView routing/public-adapter boundary threw during validation."))
            End Try
        End Sub

        Private Shared Sub ValidateSplitView(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASSplitView = MASSplitView.Create("Shell boundary proof")
                If Not control.HasShellIntegrationBoundaryForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("splitview", "SplitView.ShellIntegration", MASCommercialReadinessFindingSeverity.Error, "SplitView shell integration boundary did not prove a safe host-owned shell boundary."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASRoutingShellBoundaryClosureGate.SplitView")
                findings.Add(New MASCommercialReadinessFinding("splitview", "SplitView.ShellIntegration", MASCommercialReadinessFindingSeverity.Error, "SplitView shell integration boundary threw during validation."))
            End Try
        End Sub

    End Class

End Namespace
