Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Quality

    ''' <summary>
    ''' Friend-only proof that the Phase-1 hosting gaps were closed through real
    ''' MASControlBase RegisterChild/UnregisterChild lifecycles inside the product
    ''' controls, not through Showcase wrappers or native-panel shortcuts.
    ''' </summary>
    Friend NotInheritable Class MASHostingContractClosureGate

        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)()
            ValidateDashboardGrid(findings)
            ValidateMasterDetailView(findings)
            ValidateAppLayout(findings)
            ValidateSplitView(findings)
            Return findings
        End Function

        Private Shared Sub ValidateDashboardGrid(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASDashboardGrid = MASDashboardGrid.Create("Hosting proof")
                control.AddWidget("sales", "Sales", "42", "Hosted")
                If Not control.HasWidgetHostingContractForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("dashboardgrid", "DashboardGrid.ChildHosting", MASCommercialReadinessFindingSeverity.Error, "DashboardGrid hosted-widget contract did not register, snapshot, and unregister a real MAS child."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASHostingContractClosureGate.DashboardGrid")
                findings.Add(New MASCommercialReadinessFinding("dashboardgrid", "DashboardGrid.ChildHosting", MASCommercialReadinessFindingSeverity.Error, "DashboardGrid hosted-widget contract threw during validation."))
            End Try
        End Sub

        Private Shared Sub ValidateMasterDetailView(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASMasterDetailView = MASMasterDetailView.Create("Hosting proof")
                control.AddItem("case-1", "Case 1", "Detail", "Detail host", "Hosted detail")
                If Not control.HasDetailHostingContractForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("masterdetail", "MasterDetail.DetailHosting", MASCommercialReadinessFindingSeverity.Error, "MasterDetailView detail-host contract did not register, snapshot, and unregister a real MAS child."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASHostingContractClosureGate.MasterDetail")
                findings.Add(New MASCommercialReadinessFinding("masterdetail", "MasterDetail.DetailHosting", MASCommercialReadinessFindingSeverity.Error, "MasterDetailView detail-host contract threw during validation."))
            End Try
        End Sub

        Private Shared Sub ValidateAppLayout(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASAppLayout = MASAppLayout.Create("Hosting proof")
                If Not control.HasSlotHostingContractForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("applayout", "AppLayout.ChildSlotHosting", MASCommercialReadinessFindingSeverity.Error, "AppLayout slot-hosting contract did not register, snapshot, and unregister real MAS children."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASHostingContractClosureGate.AppLayout")
                findings.Add(New MASCommercialReadinessFinding("applayout", "AppLayout.ChildSlotHosting", MASCommercialReadinessFindingSeverity.Error, "AppLayout slot-hosting contract threw during validation."))
            End Try
        End Sub

        Private Shared Sub ValidateSplitView(findings As List(Of MASCommercialReadinessFinding))
            Try
                Dim control As MASSplitView = MASSplitView.Create("Hosting proof")
                If Not control.HasPaneHostingContractForTests() Then
                    findings.Add(New MASCommercialReadinessFinding("splitview", "SplitView.ChildContentHosting", MASCommercialReadinessFindingSeverity.Error, "SplitView pane-hosting contract did not register, snapshot, and unregister real MAS children."))
                End If
            Catch ex As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowDiagnosticOnly(ex, "MASHostingContractClosureGate.SplitView")
                findings.Add(New MASCommercialReadinessFinding("splitview", "SplitView.ChildContentHosting", MASCommercialReadinessFindingSeverity.Error, "SplitView pane-hosting contract threw during validation."))
            End Try
        End Sub

    End Class

End Namespace
