Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel

Namespace Nexamas.UI.Certification

    ''' <summary>
    ''' Immutable internal certification manifest for the official Nexamas UI commercial evidence surface.
    ''' </summary>
    ''' <remarks>
    ''' This manifest aggregates already-owned closure facts. It does not execute platform gates,
    ''' read report files, inspect source files, execute render verification captures, create controls,
    ''' schedule frames, query telemetry, allocate bitmaps, or mutate platform state.
    ''' </remarks>
    Friend NotInheritable Class NexamasUICertificationManifest
        Private ReadOnly _entries As IReadOnlyList(Of NexamasUICertificationEntry)
        Private ReadOnly _requiredGateNames As IReadOnlyList(Of String)
        Private ReadOnly _evidenceReportNames As IReadOnlyList(Of String)
        Private ReadOnly _ownershipContracts As IReadOnlyList(Of String)
        Private ReadOnly _proofMatrix As MASCertificationProofMatrix

        Friend Sub New(status As NexamasUICertificationStatus,
                       certificationName As String,
                       certificationId As String,
                       entries As IEnumerable(Of NexamasUICertificationEntry),
                       requiredGateNames As IEnumerable(Of String),
                       evidenceReportNames As IEnumerable(Of String),
                       ownershipContracts As IEnumerable(Of String),
                       hasOfficialCenterSurface As Boolean,
                       hasDemoLogicIsolation As Boolean,
                       hasCommercialGateRegistration As Boolean,
                       expectedSdkHarnessCount As Integer,
                       summary As String,
                       Optional proofMatrix As MASCertificationProofMatrix = Nothing)
            Me.Status = status
            Me.CertificationName = NormalizeText(certificationName)
            Me.CertificationId = NormalizeText(certificationId)
            _entries = New ReadOnlyCollection(Of NexamasUICertificationEntry)(NormalizeEntries(entries))
            _requiredGateNames = New ReadOnlyCollection(Of String)(NormalizeList(requiredGateNames))
            _evidenceReportNames = New ReadOnlyCollection(Of String)(NormalizeList(evidenceReportNames))
            _ownershipContracts = New ReadOnlyCollection(Of String)(NormalizeList(ownershipContracts))
            Me.HasOfficialCenterSurface = hasOfficialCenterSurface
            Me.HasDemoLogicIsolation = hasDemoLogicIsolation
            Me.HasCommercialGateRegistration = hasCommercialGateRegistration
            Me.ExpectedSdkHarnessCount = expectedSdkHarnessCount
            Me.Summary = NormalizeText(summary)
            _proofMatrix = If(proofMatrix, MASCertificationProofMatrix.DeclaredOnly())
        End Sub

        Friend ReadOnly Property Status As NexamasUICertificationStatus
        Friend ReadOnly Property CertificationName As String
        Friend ReadOnly Property CertificationId As String
        Friend ReadOnly Property HasOfficialCenterSurface As Boolean
        Friend ReadOnly Property HasDemoLogicIsolation As Boolean
        Friend ReadOnly Property HasCommercialGateRegistration As Boolean
        Friend ReadOnly Property ExpectedSdkHarnessCount As Integer
        Friend ReadOnly Property Summary As String

        Friend ReadOnly Property ProofMatrix As MASCertificationProofMatrix
            Get
                Return _proofMatrix
            End Get
        End Property

        Friend ReadOnly Property Entries As IReadOnlyList(Of NexamasUICertificationEntry)
            Get
                Return _entries
            End Get
        End Property

        Friend ReadOnly Property RequiredGateNames As IReadOnlyList(Of String)
            Get
                Return _requiredGateNames
            End Get
        End Property

        Friend ReadOnly Property EvidenceReportNames As IReadOnlyList(Of String)
            Get
                Return _evidenceReportNames
            End Get
        End Property

        Friend ReadOnly Property OwnershipContracts As IReadOnlyList(Of String)
            Get
                Return _ownershipContracts
            End Get
        End Property

        Friend ReadOnly Property CertifiedEntryCount As Integer
            Get
                Dim count As Integer = 0
                For Each entry As NexamasUICertificationEntry In Entries
                    If entry IsNot Nothing AndAlso entry.IsCertified Then count += 1
                Next
                Return count
            End Get
        End Property

        Friend ReadOnly Property BlockedEntryCount As Integer
            Get
                Dim count As Integer = 0
                For Each entry As NexamasUICertificationEntry In Entries
                    If entry Is Nothing OrElse entry.HasBlocker Then count += 1
                Next
                Return count
            End Get
        End Property

        Friend ReadOnly Property HasCompleteCommercialEvidenceSurface As Boolean
            Get
                Return Not String.IsNullOrWhiteSpace(CertificationName) AndAlso
                       Not String.IsNullOrWhiteSpace(CertificationId) AndAlso
                       Entries.Count >= 21 AndAlso
                       RequiredGateNames.Count >= 10 AndAlso
                       EvidenceReportNames.Count >= 20 AndAlso
                       OwnershipContracts.Count >= 23 AndAlso
                       ExpectedSdkHarnessCount = 88 AndAlso
                       HasOfficialCenterSurface AndAlso
                       HasDemoLogicIsolation AndAlso
                       HasCommercialGateRegistration AndAlso
                       AllEntriesHaveEvidencePointers()
            End Get
        End Property

        Friend ReadOnly Property IsCertified As Boolean
            Get
                Return HasCompleteCommercialEvidenceSurface AndAlso
                       ProofMatrix IsNot Nothing AndAlso
                       ProofMatrix.HasFullCommercialProof AndAlso
                       Status = NexamasUICertificationStatus.Certified
            End Get
        End Property

        Friend ReadOnly Property HasCertificationBlocker As Boolean
            Get
                Return Status = NexamasUICertificationStatus.Blocked OrElse
                       Status = NexamasUICertificationStatus.IncompleteGovernance OrElse
                       BlockedEntryCount > 0 OrElse
                       Not HasCompleteCommercialEvidenceSurface
            End Get
        End Property

        Friend Shared Function CreateCurrent() As NexamasUICertificationManifest
            Return CreateFromQualityReport(MASQualityOrchestrator.Run())
        End Function

        Friend Shared Function CreateDeclaredCurrent() As NexamasUICertificationManifest
            Return CreateFromEntries(CreateCurrentEntries(),
                                     "Nexamas UI Commercial Certification Center",
                                     hasOfficialCenterSurface:=True,
                                     hasDemoLogicIsolation:=True,
                                     hasCommercialGateRegistration:=True,
                                     expectedSdkHarnessCount:=88)
        End Function

        Friend Shared Function CreateFromEntries(entries As IEnumerable(Of NexamasUICertificationEntry),
                                                 certificationName As String,
                                                 hasOfficialCenterSurface As Boolean,
                                                 hasDemoLogicIsolation As Boolean,
                                                 hasCommercialGateRegistration As Boolean,
                                                 expectedSdkHarnessCount As Integer) As NexamasUICertificationManifest
            Dim normalizedEntries As IReadOnlyList(Of NexamasUICertificationEntry) = New ReadOnlyCollection(Of NexamasUICertificationEntry)(NormalizeEntries(entries))
            Dim proofMatrix As MASCertificationProofMatrix = MASCertificationProofMatrix.DeclaredOnly()
            Dim status As NexamasUICertificationStatus = ResolveStatus(normalizedEntries, hasOfficialCenterSurface, hasDemoLogicIsolation, hasCommercialGateRegistration, expectedSdkHarnessCount)
            status = MergeStatusWithProofMatrix(status, proofMatrix)
            Dim name As String = If(String.IsNullOrWhiteSpace(certificationName),
                                    "Nexamas UI Commercial Certification Center",
                                    certificationName.Trim())

            Return New NexamasUICertificationManifest(
                status,
                name,
                "MAS-PLATFORM-COMMERCIAL-CERTIFICATION-CENTER-2026-06-19",
                normalizedEntries,
                CreateGateNames(normalizedEntries),
                CreateReportNames(normalizedEntries),
                CreateOwnershipContracts(),
                hasOfficialCenterSurface,
                hasDemoLogicIsolation,
                hasCommercialGateRegistration,
                expectedSdkHarnessCount,
                ResolveSummary(status, normalizedEntries),
                proofMatrix)
        End Function

        Friend Shared Function CreateFromQualityReport(report As MASQualityReport) As NexamasUICertificationManifest
            Dim entries As IReadOnlyList(Of NexamasUICertificationEntry) = CreateCurrentEntries()
            If report IsNot Nothing Then entries = ApplyQualityGateResults(entries, report)

            Dim proofMatrix As MASCertificationProofMatrix = If(report Is Nothing, MASCertificationProofMatrix.DeclaredOnly(), report.ProofMatrix)
            Dim status As NexamasUICertificationStatus = ResolveStatus(entries,
                                                                         hasOfficialCenterSurface:=True,
                                                                         hasDemoLogicIsolation:=True,
                                                                         hasCommercialGateRegistration:=True,
                                                                         expectedSdkHarnessCount:=88)
            status = MergeStatusWithQualityReport(status, report)
            status = MergeStatusWithProofMatrix(status, proofMatrix)

            Return New NexamasUICertificationManifest(
                status,
                "Nexamas UI Commercial Certification Center",
                "MAS-PLATFORM-COMMERCIAL-CERTIFICATION-CENTER-2026-06-19",
                entries,
                CreateGateNames(entries),
                CreateReportNames(entries),
                CreateOwnershipContracts(),
                hasOfficialCenterSurface:=True,
                hasDemoLogicIsolation:=True,
                hasCommercialGateRegistration:=True,
                expectedSdkHarnessCount:=88,
                summary:=ResolveQualityBackedSummary(status, entries, report),
                proofMatrix:=proofMatrix)
        End Function

        Private Shared Function MergeStatusWithProofMatrix(currentStatus As NexamasUICertificationStatus,
                                                            proofMatrix As MASCertificationProofMatrix) As NexamasUICertificationStatus
            If currentStatus = NexamasUICertificationStatus.IncompleteGovernance OrElse
               currentStatus = NexamasUICertificationStatus.Blocked Then Return currentStatus

            If proofMatrix Is Nothing OrElse Not proofMatrix.HasAnyProof Then Return NexamasUICertificationStatus.EvidenceDeclared
            If proofMatrix.HasBlockingProof Then Return NexamasUICertificationStatus.Blocked
            If Not proofMatrix.HasFullCommercialProof Then Return NexamasUICertificationStatus.SourceCertifiedOnly
            Return currentStatus
        End Function

        Private Shared Function MergeStatusWithQualityReport(currentStatus As NexamasUICertificationStatus,
                                                                  report As MASQualityReport) As NexamasUICertificationStatus
            If report Is Nothing Then Return currentStatus

            If report.Status = NexamasUICertificationStatus.IncompleteGovernance Then Return NexamasUICertificationStatus.IncompleteGovernance
            If report.Status = NexamasUICertificationStatus.Blocked Then Return NexamasUICertificationStatus.Blocked
            If currentStatus = NexamasUICertificationStatus.IncompleteGovernance OrElse currentStatus = NexamasUICertificationStatus.Blocked Then Return currentStatus
            If report.Status = NexamasUICertificationStatus.CertifiedWithMonitoring Then Return NexamasUICertificationStatus.CertifiedWithMonitoring
            Return currentStatus
        End Function

        Private Shared Function ResolveQualityBackedSummary(status As NexamasUICertificationStatus,
                                                            entries As IReadOnlyList(Of NexamasUICertificationEntry),
                                                            report As MASQualityReport) As String
            Dim baseSummary As String = ResolveSummary(status, entries)
            If report Is Nothing Then Return baseSummary & " Quality Orchestrator evidence was not available for this manifest build. " & MASCertificationProofMatrix.DeclaredOnly().Summary

            Return baseSummary & " " & report.Summary & " " & report.ProofMatrix.Summary
        End Function

        Private Shared Function ApplyQualityGateResults(entries As IReadOnlyList(Of NexamasUICertificationEntry),
                                                        report As MASQualityReport) As IReadOnlyList(Of NexamasUICertificationEntry)
            Dim adjusted As New List(Of NexamasUICertificationEntry)()
            If entries Is Nothing Then Return New ReadOnlyCollection(Of NexamasUICertificationEntry)(adjusted)

            For Each entry As NexamasUICertificationEntry In entries
                If entry Is Nothing Then Continue For

                Dim matchingResults As IReadOnlyList(Of MASQualityGateResult) = report.FindByCertificationSystemKey(entry.SystemKey)
                If matchingResults.Count = 0 Then
                    adjusted.Add(CreateDeclaredEntry(entry,
                                                    "No direct Quality Orchestrator gate result matched this certification entry; the row is declared evidence only, not a gate-certified result."))
                    Continue For
                End If

                Dim status As NexamasUICertificationStatus = ResolveEntryStatusFromQualityResults(entry.Status, matchingResults)
                adjusted.Add(New NexamasUICertificationEntry(entry.SystemKey,
                                                              entry.DisplayName,
                                                              status,
                                                              entry.ClosureContractName,
                                                              entry.ClosureGateName,
                                                              entry.EvidenceReportName,
                                                              AppendQualitySummary(entry.Summary, matchingResults)))
            Next

            Return New ReadOnlyCollection(Of NexamasUICertificationEntry)(adjusted)
        End Function

        Private Shared Function CreateDeclaredEntry(entry As NexamasUICertificationEntry,
                                                        reason As String) As NexamasUICertificationEntry
            If entry Is Nothing Then Return Nothing
            Dim summary As String = NormalizeText(entry.Summary)
            Dim normalizedReason As String = NormalizeText(reason)
            If normalizedReason.Length > 0 Then
                summary = If(summary.Length = 0, normalizedReason, summary & " " & normalizedReason)
            End If

            Return NexamasUICertificationEntry.EvidenceDeclared(entry.SystemKey,
                                                                  entry.DisplayName,
                                                                  entry.ClosureContractName,
                                                                  entry.ClosureGateName,
                                                                  entry.EvidenceReportName,
                                                                  summary)
        End Function

        Private Shared Function ResolveEntryStatusFromQualityResults(originalStatus As NexamasUICertificationStatus,
                                                                     results As IReadOnlyList(Of MASQualityGateResult)) As NexamasUICertificationStatus
            If originalStatus = NexamasUICertificationStatus.Blocked OrElse originalStatus = NexamasUICertificationStatus.IncompleteGovernance Then Return originalStatus

            Dim monitored As Boolean = (originalStatus = NexamasUICertificationStatus.CertifiedWithMonitoring)
            For Each result As MASQualityGateResult In results
                If result Is Nothing Then Continue For
                If result.CertificationStatus = NexamasUICertificationStatus.Blocked Then Return NexamasUICertificationStatus.Blocked
                If result.CertificationStatus = NexamasUICertificationStatus.IncompleteGovernance Then Return NexamasUICertificationStatus.IncompleteGovernance
                If result.CertificationStatus = NexamasUICertificationStatus.CertifiedWithMonitoring Then monitored = True
            Next

            If monitored Then Return NexamasUICertificationStatus.CertifiedWithMonitoring
            Return NexamasUICertificationStatus.Certified
        End Function

        Private Shared Function AppendQualitySummary(summary As String,
                                                     results As IReadOnlyList(Of MASQualityGateResult)) As String
            Dim baseSummary As String = NormalizeText(summary)
            If results Is Nothing OrElse results.Count = 0 Then Return baseSummary

            Dim fragments As New List(Of String)()
            For Each result As MASQualityGateResult In results
                If result Is Nothing Then Continue For
                Dim text As String = NormalizeText(result.DisplayName & " => " & result.Status.ToString() & ". " & result.Summary)
                If text.Length > 0 Then fragments.Add(text)
            Next

            If fragments.Count = 0 Then Return baseSummary
            Return baseSummary & " Quality Orchestrator: " & String.Join(" | ", fragments)
        End Function


        Private Function AllEntriesHaveEvidencePointers() As Boolean
            For Each entry As NexamasUICertificationEntry In Entries
                If entry Is Nothing OrElse Not entry.HasCompleteEvidencePointer Then Return False
            Next
            Return True
        End Function

        Private Shared Function ResolveStatus(entries As IReadOnlyList(Of NexamasUICertificationEntry),
                                              hasOfficialCenterSurface As Boolean,
                                              hasDemoLogicIsolation As Boolean,
                                              hasCommercialGateRegistration As Boolean,
                                              expectedSdkHarnessCount As Integer) As NexamasUICertificationStatus
            If entries Is Nothing OrElse entries.Count < 21 OrElse
               Not hasOfficialCenterSurface OrElse
               Not hasDemoLogicIsolation OrElse
               Not hasCommercialGateRegistration OrElse
               expectedSdkHarnessCount <> 88 Then
                Return NexamasUICertificationStatus.IncompleteGovernance
            End If

            Dim monitored As Boolean = False
            For Each entry As NexamasUICertificationEntry In entries
                If entry Is Nothing OrElse entry.Status = NexamasUICertificationStatus.IncompleteGovernance Then
                    Return NexamasUICertificationStatus.IncompleteGovernance
                End If

                If entry.Status = NexamasUICertificationStatus.Blocked Then
                    Return NexamasUICertificationStatus.Blocked
                End If

                If entry.Status = NexamasUICertificationStatus.CertifiedWithMonitoring OrElse
                   entry.Status = NexamasUICertificationStatus.EvidenceDeclared OrElse
                   entry.Status = NexamasUICertificationStatus.SourceCertifiedOnly Then
                    monitored = True
                End If
            Next

            If monitored Then Return NexamasUICertificationStatus.CertifiedWithMonitoring
            Return NexamasUICertificationStatus.Certified
        End Function

        Private Shared Function ResolveSummary(status As NexamasUICertificationStatus,
                                               entries As IReadOnlyList(Of NexamasUICertificationEntry)) As String
            Select Case status
                Case NexamasUICertificationStatus.Certified
                    Return "All core Nexamas UI commercial governance and product-showcase capability coverage areas are certified and visible through the official internal evidence surface."
                Case NexamasUICertificationStatus.CertifiedWithMonitoring
                    Return "Nexamas UI commercial governance is passable with warnings: gate-backed areas are certified, while declared-only evidence rows remain under monitoring until a direct Quality Orchestrator result backs them."
                Case NexamasUICertificationStatus.SourceCertifiedOnly
                    Return "Nexamas UI has source/governance certification evidence only. Runtime, package, and packed-consumer proofs are not attached to this manifest, so this is not a full release certificate."
                Case NexamasUICertificationStatus.Blocked
                    Return "Nexamas UI commercial certification is blocked by at least one certified-system evidence entry."
                Case Else
                    Return "Nexamas UI commercial certification is incomplete because the evidence surface or governance chain is not fully registered."
            End Select
        End Function

        Private Shared Function CreateCurrentEntries() As IReadOnlyList(Of NexamasUICertificationEntry)
            Return New ReadOnlyCollection(Of NexamasUICertificationEntry)(New List(Of NexamasUICertificationEntry) From {
                NexamasUICertificationEntry.EvidenceDeclared(
                    "quality-orchestrator",
                    "Quality Orchestrator",
                    "MASQualityOrchestrator",
                    "quality-orchestrator",
                    "docs/QUALITY.md",
                    "Quality gates are now aggregated through a single internal orchestrator before certification status is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "quality-asset-presence",
                    "Quality Asset Presence Gate",
                    "MASQualityAssetPresenceGate",
                    "quality-asset-presence",
                    "docs/QUALITY.md",
                    "The product tree now has a strict asset-presence gate that validates project-declared scripts, docs, samples, CI, packaging, and resource files before certification evidence is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "architecture-validation",
                    "Architecture Registry Validation",
                    "MASArchitectureValidator",
                    "architecture-validation",
                    "docs/QUALITY.md",
                    "The registered component architecture catalog is validated before product certification accepts Application, Layout, Render Verification, and component ownership evidence."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "application-ownership-closure",
                    "Application Ownership Closure Gate",
                    "MASApplicationOwnershipClosureAudit",
                    "application-ownership-closure",
                    "MAS_APPLICATION_OWNERSHIP_CLOSURE_2026_07_01.md",
                    "Application control admission, retained layout sessions, and framework geometry mutation are now proven through a read-only internal ownership gate before certification status is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "component-coverage-map",
                    "Component Registry Coverage Map",
                    "MASQualityComponentCoverageMap",
                    "component-coverage-map",
                    "docs/QUALITY.md",
                    "Every MASComponentRegistry descriptor is now classified against direct render scenarios, family render scenarios, or named contract/system proof coverage."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "render-verification-coverage",
                    "Render Verification Coverage Graph",
                    "MASRenderVerificationCoverageAudit",
                    "render-verification-coverage",
                    "docs/QUALITY.md",
                    "Render Verification now performs an exact graph comparison between target catalog scenarios, capture-scene registration, and MASComponentRegistry coverage entries."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "render-verification-readiness",
                    "Render Verification Readiness Gate",
                    "MASRenderVerificationGate",
                    "render-verification-readiness",
                    "docs/QUALITY.md",
                    "Render Verification target identity, scenario uniqueness, output file naming, capture-scene ownership, DPI, dimensions, theme keys, and baseline-store ownership are validated before visual evidence is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "surface-material-proof",
                    "Surface Material Proof Gate",
                    "MASRenderVerificationSurfaceMaterialProofAudit",
                    "surface-material-proof",
                    "docs/QUALITY.md",
                    "Runtime surface visual consumers and public surface gateway members are matched to official Render Verification scenarios and capture scenes before material proof is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "render-verification-element-coverage-closure",
                    "Render Verification Element Coverage Closure Gate",
                    "MASRenderVerificationElementCoverageClosureAudit",
                    "render-verification-element-coverage-closure",
                    "MAS_RENDER_VERIFICATION_ELEMENT_COVERAGE_CLOSURE_2026_07_01.md",
                    "The Render Verification dashboard row model is now closed against MASComponentRegistry, MASQualityComponentCoverageMap, target catalog scenarios, and capture-scene registration so every descriptor has a visible evidence row."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "size-layout-runtime-verification",
                    "Size/Layout Runtime Verification Gate",
                    "MASSizeLayoutRuntimeVerificationAudit",
                    "size-layout-runtime-verification",
                    "docs/QUALITY.md",
                    "Size/Layout now has a runtime verification gate for responsive modes, runtime profiles, DPI conversion, tiny bounds, hit/visual overflow contracts, Composition runtime stress recipes, and existing layout governance audits."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "size-layout-element-closure",
                    "Size/Layout Element Closure Gate",
                    "MASSizeLayoutElementClosureAudit",
                    "size-layout-element-closure",
                    "MAS_SIZE_LAYOUT_ELEMENT_CLOSURE_2026_07_01.md",
                    "Every MASComponentRegistry descriptor is now closed against responsive consumption evidence, and every registered visual control is verified against intrinsic-size and Friend-only layout participant contracts."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "render-hit-bounds-closure",
                    "Render / Hit Bounds Closure Gate",
                    "MASRenderHitBoundsClosureAudit",
                    "render-hit-bounds-closure",
                    "MAS_RENDER_HIT_BOUNDS_CLOSURE_2026_07_01.md",
                    "Render-time bounds, slot semantic rectangles, clip routing, and pointer hit-testing are now verified against the single MASLayoutSlot-owned geometry chain."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "localization-runtime-ownership",
                    "Localization / RTL Runtime Ownership Gate",
                    "MASLocalizationRuntimeOwnershipAudit",
                    "localization-runtime-ownership",
                    "MAS_LOCALIZATION_RUNTIME_OWNERSHIP_CLOSURE_2026_07_01.md",
                    "Localization / RTL now has a Friend-owned runtime text resolver, RTL/mirrored-layout culture proof, and a public host boundary that exposes AttachPage only without opening catalogs or translation APIs."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "output-application-route",
                    "Output Product Route Gate",
                    "MASOutputApplicationRouteAudit",
                    "output-application-route",
                    "MAS_OUTPUT_APPLICATION_ROUTE_CLOSURE_2026_07_01.md",
                    "Output now has a public MASApplication.Output facade with explicit request/result/capability catalog contracts, render-backed PNG visual capture, directory/file destinations, overwrite protection, and a product evidence bundle while Chart/Visualization, Report/Print, and Render Verification internals remain governed."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "dead-path-closure",
                    "Dead Path / Parallel Path Closure Gate",
                    "MASDeadPathClosureAudit",
                    "dead-path-closure",
                    "MAS_DEAD_PATH_PARALLEL_PATH_CLOSURE_2026_07_01.md",
                    "The source tree is now checked for missing declared assets, duplicate project Includes, unowned active Nexamas UI source files, and root-level generated-output paths before final architecture closure is trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "performance-diagnostics-orchestration",
                    "Performance/Diagnostics Orchestration Gate",
                    "MASPerformanceDiagnosticsOrchestrationAudit",
                    "performance-diagnostics-orchestration",
                    "docs/QUALITY.md",
                    "PerformanceSystem and Diagnostics Dashboard now have a read-only orchestration gate for budgets, immutable snapshots, dashboard availability truth, consumer refresh counters, virtualization bridge, and performance release certification."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "certification-orchestration-closure",
                    "Certification Orchestration Closure Gate",
                    "MASCertificationOrchestrationClosureAudit",
                    "certification-orchestration-closure",
                    "docs/QUALITY.md",
                    "The Certification Manifest is now closed against the Quality Orchestrator graph; every orchestrated gate must map to a declared Certification entry before the manifest status can be trusted."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "performance",
                    "PerformanceSystem",
                    "MASPerformanceGovernanceClosureManifest",
                    "performance",
                    "MAS_PERFORMANCE_FINAL_CLOSURE_AUDIT_DEAD_PATH_LOCKDOWN_2026_06_18.md",
                    "Performance governance is closed through release certification and final dead-path lockdown."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "render-verification",
                    "RenderVerificationSystem",
                    "MASRenderVerificationGovernanceClosureManifest",
                    "render-verification",
                    "MAS_RENDER_VERIFICATION_FINAL_CLOSURE_EVIDENCE_GOVERNANCE_2026_06_18.md",
                    "Visual evidence governance is closed through target catalog, scene registry, inventory proof, and dashboard boundary."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "virtualization",
                    "VirtualizationSystem",
                    "MASVirtualizationGovernanceClosureManifest",
                    "virtualization",
                    "MAS_VIRTUALIZATION_FINAL_CLOSURE_COMMERCIAL_SCALE_GOVERNANCE_2026_06_18.md",
                    "Large-scale realization, measurement cache, recycle pool, scroll-to-index, and consumer catalog governance are closed."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "datagrid",
                    "MASDataGrid",
                    "MASDataGridCommercialRuntimeClosureManifest",
                    "datagrid",
                    "MAS_DATAGRID_COMMERCIAL_RUNTIME_READINESS_FINAL_CLOSURE_2026_06_19.md",
                    "DataGrid commercial runtime ownership, verification coverage, and virtualization consumption are closed."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "floatruntime",
                    "FloatRuntime / Overlay",
                    "MASFloatRuntimeGovernanceClosureManifest",
                    "floatruntime",
                    "MAS_FLOATRUNTIME_OVERLAY_GOVERNANCE_FINAL_CLOSURE_2026_06_19.md",
                    "Floating surfaces are closed through descriptor registry, lifecycle policy, input/focus routing, and presentation governance."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "sdk-release-readiness",
                    "Nexamas UI SDK Release Readiness",
                    "NexamasUISdkReleaseReadinessManifest",
                    "sdk-release-readiness",
                    "MAS_SDK_RELEASE_READINESS_PUBLIC_CONTRACT_FREEZE_2026_06_19.md",
                    "SDK public type/member contracts, package metadata, ReleaseChecklist, Certification Center, and Commercial Gate release evidence are frozen."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "final-architecture-closure",
                    "Nexamas UI Final Architecture Closure",
                    "NexamasUIFinalArchitectureClosureManifest",
                    "final-architecture-closure",
                    "NEXAMAS_UI_FINAL_ARCHITECTURE_CLOSURE_DEAD_PATH_LOCKDOWN_2026_06_20.md",
                    "Project-wide architecture boundaries, evidence-only proofs, demo isolation, public API lockdown, and dead-path closure are certified."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "commercial-gate",
                    "Nexamas UI Commercial Gate",
                    "tools/quality/Run-NexamasUIQuality.ps1",
                    "commercial-gate",
                    "README.md",
                    "The commercial gate registers and protects the closed commercial governance systems."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "sdk-harness",
                    "SDK Runtime Harness",
                    "eng/tests/Run-NexamasUISdkHarness.ps1",
                    "sdk-harness",
                    "MAS_POST_PHASE6_FOUNDATION_INTEGRITY_COHESION_AUDIT.md",
                    "The SDK runtime harness remains locked to the 88-test baseline."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-pagehost-coverage",
                    "Showcase PageHost Coverage Gate",
                    "NexamasUIShowcase.PageHostCoverageGate",
                    "showcase-pagehost-coverage",
                    "SHOWCASE_COVERAGE_GATE_2026_06_22.md",
                    "The external Showcase now has a strict PageHost coverage inventory for public Nexamas UI control gateways and hidden capability decisions."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-business-controls",
                    "Chart and PropertyGrid Showcase Coverage",
                    "NexamasUIShowcase.BusinessControlPageHostCoverage",
                    "showcase-business-controls",
                    "SHOWCASE_PHASE5_BUSINESS_CONTROL_PAGEHOST_COVERAGE_2026_06_22.md",
                    "Chart Dashboard and PropertyGrid Inspector are active PageHost pages through AddChart and AddPropertyGrid public gateways."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-search-datagrid",
                    "Advanced SearchBox and DataGrid Showcase Coverage",
                    "NexamasUIShowcase.AdvancedSearchBoxDataGridCoverage",
                    "showcase-search-datagrid",
                    "SHOWCASE_PHASE6_ADVANCED_SEARCHBOX_DATAGRID_COVERAGE_2026_06_22.md",
                    "Advanced SearchBox suggestions, recent searches, filter tokens, DataGrid binding, commit, and suggestion acceptance are shown through public routes."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-surface-materials",
                    "Surface Material Live Lab Showcase Coverage",
                    "NexamasUIShowcase.SurfaceMaterialLiveLabGatewayCoverage",
                    "showcase-surface-materials",
                    "SHOWCASE_PHASE7_SURFACE_MATERIAL_LIVE_LAB_GATEWAY_COVERAGE_2026_06_22.md",
                    "Surface material switching is shown as a live public gateway lab for eligible broad-surface consumers without opening VisualSurface internals."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-services",
                    "Services Full Capabilities Showcase Coverage",
                    "NexamasUIShowcase.ServicesFullCapabilitiesCoverage",
                    "showcase-services",
                    "SHOWCASE_PHASE8_SERVICES_FULL_CAPABILITIES_COVERAGE_2026_06_22.md",
                    "Dialogs, Toasts, Tooltips, ContextMenus, Progress, FilePicker, and FileExplorer are shown through Window.Services public facades."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-certification-refresh",
                    "Certification Center Showcase Capability Refresh",
                    "NexamasUICertificationManifest",
                    "showcase-certification-refresh",
                    "SHOWCASE_PHASE9_CERTIFICATION_CENTER_CAPABILITY_REFRESH_2026_06_22.md",
                    "Certification Center now names the active Showcase capability coverage so users can see that visible pages match current Nexamas UI strength."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-diagnostics-dashboard",
                    "Diagnostics Dashboard Showcase Coverage",
                    "MASDiagnosticsDashboard.AttachDashboard",
                    "showcase-diagnostics-dashboard",
                    "SHOWCASE_PHASE10_DIAGNOSTICS_DASHBOARD_HOST_COVERAGE_2026_06_22.md",
                    "Diagnostics Dashboard is now visible through the Nexamas UI-owned AttachDashboard host route without exposing telemetry or dashboard internals."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-layout-architecture",
                    "Layout / Application Architecture Showcase Coverage",
                    "NexamasUIShowcase.ApplicationArchitecturePage",
                    "showcase-layout-architecture",
                    "SHOWCASE_PHASE11_LAYOUT_APPLICATION_ARCHITECTURE_PAGE_2026_06_22.md",
                    "Application architecture is now visible through PageHost, ApplicationPage, SplitPane, FilterBar, FormRow, Gallery, Flow, and ActionGroup public routes without opening layout internals."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-workflow-foundations",
                    "Workflow Foundations Showcase Coverage",
                    "NexamasUIShowcase.WorkflowFoundationsPage",
                    "showcase-workflow-foundations",
                    "SHOWCASE_PHASE12_WORKFLOW_FOUNDATIONS_PAGE_2026_06_22.md",
                    "Command / Action, Data Binding, and Form Validation capability boundaries are visible through public-safe action groups, inputs, validation visuals, and services without opening Friend foundation engines."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-reportprint-foundation",
                    "Report / Print Foundation Showcase Decision",
                    "NexamasUIShowcase.CommercialFoundationsPage",
                    "showcase-reportprint-foundation",
                    "SHOWCASE_PHASE13_REPORTPRINT_PLUGINMODULE_CAPABILITY_DECISIONS_2026_06_22.md",
                    "Report / Print is visible as a certified Friend-owned foundation decision without opening public print, export, PDF, report-designer, or Showcase-owned report-model routes."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-pluginmodule-foundation",
                    "Plugin / Module Foundation Showcase Decision",
                    "NexamasUIShowcase.CommercialFoundationsPage",
                    "showcase-pluginmodule-foundation",
                    "SHOWCASE_PHASE13_REPORTPRINT_PLUGINMODULE_CAPABILITY_DECISIONS_2026_06_22.md",
                    "Plugin / Module is visible as a certified Friend-owned foundation decision without opening external plugin loading, execution, or demo-owned module registry routes."),
                NexamasUICertificationEntry.EvidenceDeclared(
                    "showcase-localization-rtl-host",
                    "Localization / RTL Showcase Host Coverage",
                    "MASLocalizationRtl.AttachPage",
                    "showcase-localization-rtl-host",
                    "SHOWCASE_PHASE14_LOCALIZATION_RTL_HOST_COVERAGE_2026_06_22.md",
                    "Localization / RTL is visible through the Nexamas UI-owned AttachPage host route without exposing snapshots, catalogs, thread-culture mutation, or translation APIs.")
            })
        End Function

        Private Shared Function CreateGateNames(entries As IEnumerable(Of NexamasUICertificationEntry)) As IReadOnlyList(Of String)
            Dim names As New List(Of String)()
            If entries IsNot Nothing Then
                For Each entry As NexamasUICertificationEntry In entries
                    If entry Is Nothing Then Continue For
                    AddUnique(names, entry.ClosureGateName)
                Next
            End If
            Return New ReadOnlyCollection(Of String)(names)
        End Function

        Private Shared Function CreateReportNames(entries As IEnumerable(Of NexamasUICertificationEntry)) As IReadOnlyList(Of String)
            Dim names As New List(Of String)()
            If entries IsNot Nothing Then
                For Each entry As NexamasUICertificationEntry In entries
                    If entry Is Nothing Then Continue For
                    AddUnique(names, entry.EvidenceReportName)
                Next
            End If
            Return New ReadOnlyCollection(Of String)(names)
        End Function

        Private Shared Function CreateOwnershipContracts() As IReadOnlyList(Of String)
            Return New ReadOnlyCollection(Of String)(New List(Of String) From {
                "MASPerformanceGovernanceClosureManifest",
                "MASRenderVerificationGovernanceClosureManifest",
                "MASVirtualizationGovernanceClosureManifest",
                "MASDataGridCommercialRuntimeClosureManifest",
                "MASFloatRuntimeGovernanceClosureManifest",
                "NexamasUISdkReleaseReadinessManifest",
                "NexamasUIFinalArchitectureClosureManifest",
                "NexamasUICertificationManifest",
                "NexamasUICertificationCenterPage",
                "MASQualityOrchestrator",
                "MASQualityReport",
                "MASQualityGateResult",
                "MASQualityGateStatus",
                "MASQualityAssetPresenceGate",
                "MASApplicationOwnershipClosureAudit",
                "MASApplicationOwnershipClosureReport",
                "MASQualityComponentCoverageMap",
                "MASQualityComponentCoverageReport",
                "MASQualityComponentCoverageEntry",
                "MASQualityComponentCoverageKind",
                "MASRenderVerificationCoverageAudit",
                "MASRenderVerificationCoverageReport",
                "MASRenderVerificationCoverageFinding",
                "MASRenderVerificationCoverageFindingKind",
                "MASSizeLayoutRuntimeVerificationAudit",
                "MASSizeLayoutRuntimeVerificationFindingSeverity",
                "MASSizeLayoutRuntimeVerificationFindingKind",
                "MASSizeLayoutRuntimeVerificationFinding",
                "MASSizeLayoutRuntimeVerificationReport",
                "MASCompositionRuntimeStressVerificationAudit",
                "MASCompositionRuntimeStressFindingSeverity",
                "MASCompositionRuntimeStressFindingKind",
                "MASCompositionRuntimeStressFinding",
                "MASCompositionRuntimeStressReport",
                "MASSizeLayoutElementClosureAudit",
                "MASSizeLayoutElementClosureReport",
                "MASSizeLayoutElementClosureFinding",
                "MASSizeLayoutElementClosureFindingSeverity",
                "MASPerformanceDiagnosticsOrchestrationAudit",
                "MASPerformanceDiagnosticsOrchestrationReport",
                "MASPerformanceDiagnosticsFinding",
                "MASPerformanceDiagnosticsFindingKind",
                "MASPerformanceDiagnosticsFindingSeverity",
                "MASCertificationOrchestrationClosureAudit",
                "MASCertificationOrchestrationClosureReport",
                "NexamasUICertification",
                "NexamasUICertification.AttachCenter",
                "NexamasUIShowcase.PageHostCoverageGate",
                "NexamasUIShowcase.ChartDashboard",
                "NexamasUIShowcase.PropertyGridInspector",
                "NexamasUIShowcase.AdvancedSearchBoxDataGridCoverage",
                "NexamasUIShowcase.SurfaceMaterialLiveLabGatewayCoverage",
                "NexamasUIShowcase.ServicesFullCapabilitiesCoverage",
                "NexamasUIShowcase.DiagnosticsDashboardHostCoverage",
                "NexamasUIShowcase.ApplicationArchitecturePage",
                "NexamasUIShowcase.WorkflowFoundationsPage",
                "NexamasUIShowcase.CommercialFoundationsPage",
                "NexamasUIShowcase.ReportPrintFoundationDecision",
                "NexamasUIShowcase.PluginModuleFoundationDecision",
                "NexamasUIShowcase.LocalizationRtlHostCoverage",
                "MASLocalizationRtl",
                "MASLocalizationRtl.AttachPage",
                "MASDiagnosticsDashboard",
                "MASDiagnosticsDashboard.AttachDashboard"
            })
        End Function

        Private Shared Sub AddUnique(values As List(Of String), value As String)
            Dim normalized As String = NormalizeText(value)
            If normalized.Length > 0 AndAlso Not values.Contains(normalized) Then values.Add(normalized)
        End Sub

        Private Shared Function NormalizeEntries(entries As IEnumerable(Of NexamasUICertificationEntry)) As List(Of NexamasUICertificationEntry)
            Dim result As New List(Of NexamasUICertificationEntry)()
            If entries Is Nothing Then Return result

            For Each entry As NexamasUICertificationEntry In entries
                If entry IsNot Nothing Then result.Add(entry)
            Next

            Return result
        End Function

        Private Shared Function NormalizeList(values As IEnumerable(Of String)) As List(Of String)
            Dim result As New List(Of String)()
            If values Is Nothing Then Return result

            For Each value As String In values
                AddUnique(result, value)
            Next

            Return result
        End Function

        Private Shared Function NormalizeText(value As String) As String
            Return If(value, String.Empty).Trim()
        End Function
    End Class

End Namespace
