Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Quality

    ''' <summary>
    ''' Central friend-only manifest that states where product-control documentation,
    ''' consumer-safe sample notes, and evidence-pack boundaries live. The manifest
    ''' records both CompactPreview documentation boundaries and targeted ProductionReady
    ''' documentation boundaries.
    ''' </summary>
    Friend NotInheritable Class MASDocumentationSampleEvidenceManifest

        Private Const ExpectedProductControlCount As Integer = 8
        Private ReadOnly _records As IReadOnlyList(Of MASDocumentationSampleEvidenceRecord)

        Private Sub New(records As IEnumerable(Of MASDocumentationSampleEvidenceRecord))
            Dim normalized As New List(Of MASDocumentationSampleEvidenceRecord)()
            If records IsNot Nothing Then
                For Each record As MASDocumentationSampleEvidenceRecord In records
                    If record IsNot Nothing Then normalized.Add(record)
                Next
            End If
            _records = New ReadOnlyCollection(Of MASDocumentationSampleEvidenceRecord)(normalized.ToArray())
        End Sub

        Friend ReadOnly Property Records As IReadOnlyList(Of MASDocumentationSampleEvidenceRecord)
            Get
                Return _records
            End Get
        End Property

        Friend ReadOnly Property Count As Integer
            Get
                Return _records.Count
            End Get
        End Property

        Friend ReadOnly Property HasExpectedProductControlCoverage As Boolean
            Get
                Return Count = ExpectedProductControlCount AndAlso
                       FindById("treegrid") IsNot Nothing AndAlso
                       FindById("pivottable") IsNot Nothing AndAlso
                       FindById("kanban") IsNot Nothing AndAlso
                       FindById("agenda") IsNot Nothing AndAlso
                       FindById("dashboardgrid") IsNot Nothing AndAlso
                       FindById("masterdetail") IsNot Nothing AndAlso
                       FindById("applayout") IsNot Nothing AndAlso
                       FindById("splitview") IsNot Nothing
            End Get
        End Property

        Friend Function FindById(componentId As String) As MASDocumentationSampleEvidenceRecord
            Dim normalized As String = If(componentId, String.Empty).Trim()
            If normalized.Length = 0 Then Return Nothing

            For Each record As MASDocumentationSampleEvidenceRecord In _records
                If record IsNot Nothing AndAlso String.Equals(record.ComponentId, normalized, System.StringComparison.OrdinalIgnoreCase) Then
                    Return record
                End If
            Next

            Return Nothing
        End Function

        Friend Shared Function CreateDefault() As MASDocumentationSampleEvidenceManifest
            Dim records As New List(Of MASDocumentationSampleEvidenceRecord)()

            records.Add(CreateRecord("treegrid", "TreeGrid", "treegrid", "ProductionReady TreeGrid evidence: hierarchical source projection, sort/filter/edit contracts, bounded row-window proof, Friend-only source write-back adapter, incremental source-update proof, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("pivottable", "PivotTable", "pivottable", "ProductionReady PivotTable evidence: pivot source projection, aggregation, drilldown/export snapshot, bounded matrix-window proof, deterministic multi-level grouping policy, in-memory export writer policy, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("kanban", "KanbanBoard", "kanban", "ProductionReady Kanban evidence: source projection, reorder/persistence, bounded drop rules, rejected-drop feedback, intentional source-detach write-back policy, bounded large-board window proof, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("agenda", "AgendaView", "agenda", "ProductionReady AgendaView evidence: overlap layout, day/week/month range views, source/range windowing, recurrence/time-zone visual boundary policy, Friend-only event move/resize contracts, public adapter non-exposure, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("dashboardgrid", "DashboardGrid", "dashboardgrid", "ProductionReady dashboard layout evidence: widget layout persistence, reorder/resize, bounded widget-window proof, hosted-widget lifecycle, provider-refresh state, provider adapter non-exposure, keyboard/a11y resize thresholds, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("masterdetail", "MasterDetailView", "masterdetail", "ProductionReady master/detail evidence: source projection, selected-key retention, snapshot/restore, detail-host lifecycle, empty/error state foundation, bounded item-window proof, routing/public-adapter boundary, adapter non-exposure, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("applayout", "AppLayout", "applayout", "ProductionReady application-slot layout evidence: snapshot/restore, child-slot lifecycle, routing/page boundary, responsive host-adoption sample, benchmark baseline/threshold, and release-freeze closure"))
            records.Add(CreateRecord("splitview", "SplitView", "splitview", "ProductionReady split-surface evidence: ratio/collapse snapshot/restore, pane-host lifecycle, keyboard splitter, shell boundary, host-adoption sample, benchmark baseline/threshold, and release-freeze closure"))

            Return New MASDocumentationSampleEvidenceManifest(records)
        End Function

        Private Shared Function CreateRecord(componentId As String,
                                             displayName As String,
                                             slug As String,
                                             evidenceSummary As String) As MASDocumentationSampleEvidenceRecord
            Return New MASDocumentationSampleEvidenceRecord(
                componentId,
                displayName,
                "docs/product/product-controls/" & slug & ".md",
                "docs/examples/product-controls/" & slug & "-sample.md",
                "docs/quality-proof/product-controls-evidence-pack.md",
                If(IsPromotedProductionControl(componentId), "Documented as explicitly promoted ProductionReady after all control-specific gaps for TreeGrid/PivotTable/KanbanBoard/AgendaView/DashboardGrid/MasterDetailView/AppLayout/SplitView are closed; no governed product-size controls remain in CompactPreview.", "Documented as CompactPreview with explicit blockers before ProductionReady marketing."),
                "Public add gateway sample only; Friend/internal source, window, and proof APIs remain excluded from consumer samples.",
                evidenceSummary & "; measured runtime benchmark and baseline/threshold policy remain governed by the quality evidence pack.")
        End Function

        Private Shared Function IsPromotedProductionControl(componentId As String) As Boolean
            Return String.Equals(componentId, "treegrid", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "pivottable", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "kanban", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "agenda", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "dashboardgrid", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "masterdetail", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "applayout", System.StringComparison.OrdinalIgnoreCase) OrElse
                   String.Equals(componentId, "splitview", System.StringComparison.OrdinalIgnoreCase)
        End Function

    End Class

End Namespace
