Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Quality

    ''' <summary>
    ''' Central rule manifest for moving product-size controls beyond CompactPreview.
    ''' It keeps promotion criteria in one place instead of scattering production
    ''' decisions through individual controls or Showcase code.
    ''' </summary>
    Friend NotInheritable Class MASProductionPromotionRuleManifest

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

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

        Friend ReadOnly Property Records As IReadOnlyList(Of MASProductionPromotionRuleRecord)
            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 MASProductionPromotionRuleRecord
            Dim normalized As String = If(componentId, String.Empty).Trim()
            If normalized.Length = 0 Then Return Nothing

            For Each record As MASProductionPromotionRuleRecord 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 MASProductionPromotionRuleManifest
            Dim records As New List(Of MASProductionPromotionRuleRecord)()

            records.Add(CreateDataControlRule("treegrid", "TreeGrid", "Stable-keyed source projection, Friend-only source write-back adapter, incremental add/remove/replace source updates with selection/expanded-state preservation, bounded row-window proof, sort/filter, editing lifecycle, keyboard/accessibility stress, benchmark baseline/threshold policy, public adapter non-exposure, docs/sample boundary, and final promotion/release-freeze evidence are closed for TreeGrid."))
            records.Add(CreateDataControlRule("pivottable", "PivotTable", "Source projection, aggregation, drilldown/export snapshot, bounded matrix-window proof, deterministic multi-level grouping policy, in-memory export writer policy, public adapter non-exposure, benchmark baseline/threshold policy, keyboard/accessibility stress, public sample boundary, and final promotion/release-freeze evidence are closed for PivotTable."))
            records.Add(CreateDataControlRule("kanban", "KanbanBoard", "Source projection, board snapshot/restore, bounded reorder/drop-rule contract, rejected-drop feedback, keyboard/card movement parity, intentional public source-detach write-back policy, public adapter non-exposure, large-board bounded windowing, benchmark baseline/threshold policy, public sample boundary, and final promotion/release-freeze evidence are closed for KanbanBoard."))
            records.Add(CreateDataControlRule("agenda", "AgendaView", "AgendaView production promotion is closed by Friend-only recurrence/time-zone visual boundary proof, event move/resize contract proof, source/range windowing evidence, public adapter non-exposure, benchmark baseline/threshold policy, keyboard/accessibility stress, docs/sample boundary, final commercial-readiness closure, and release-freeze evidence."))
            records.Add(CreateHostingControlRule("dashboardgrid", "DashboardGrid", "Hosted-widget lifecycle, internal provider-refresh contracts, keyboard/a11y resize thresholds, provider adapter non-exposure policy, benchmark baseline/threshold policy, public sample boundary, and final promotion/release-freeze evidence are closed for DashboardGrid."))
            records.Add(CreateHostingControlRule("masterdetail", "MasterDetailView", "Detail-host lifecycle, empty/error state foundation, bounded item-window proof, routing/public-adapter boundary, permanent visual/source-projection adapter non-exposure, benchmark baseline/threshold policy, public sample boundary, and final promotion/release-freeze evidence are closed for MasterDetailView."))
            records.Add(CreateHostingControlRule("applayout", "AppLayout", "Child-slot lifecycle, route/page ownership boundary, responsive shell host-adoption proof, real host-adoption sample evidence, benchmark baseline/threshold policy, public adapter non-applicability, and final promotion/release-freeze evidence are closed for AppLayout."))
            records.Add(CreateHostingControlRule("splitview", "SplitView", "Pane child-content lifecycle, keyboard splitter contract, shell integration boundary, real host-adoption sample evidence, benchmark baseline/threshold policy, public adapter non-applicability, and final promotion/release-freeze evidence are closed for SplitView."))

            Return New MASProductionPromotionRuleManifest(records)
        End Function

        Private Shared Function CreateDataControlRule(componentId As String,
                                                     displayName As String,
                                                     blockerSummary As String) As MASProductionPromotionRuleRecord
            Return New MASProductionPromotionRuleRecord(
                componentId,
                displayName,
                New MASProductionPromotionRequirement() {
                    MASProductionPromotionRequirement.ArchitectureRegistration,
                    MASProductionPromotionRequirement.PublicAddGateway,
                    MASProductionPromotionRequirement.RelationCoverage,
                    MASProductionPromotionRequirement.DedicatedRenderCoverage,
                    MASProductionPromotionRequirement.DataSourceOrHostingContract,
                    MASProductionPromotionRequirement.VirtualizationOrBoundedLayoutProof,
                    MASProductionPromotionRequirement.PerformanceProof,
                    MASProductionPromotionRequirement.PublicAdapterPolicy,
                    MASProductionPromotionRequirement.DocumentationAndSamples,
                    MASProductionPromotionRequirement.MeasuredRuntimeBenchmark,
                    MASProductionPromotionRequirement.BenchmarkBaselineThresholdPolicy,
                    MASProductionPromotionRequirement.KeyboardAccessibilityStressProof,
                    MASProductionPromotionRequirement.RuntimeFaultStrictMode,
                    MASProductionPromotionRequirement.TimeMotionOwnership,
                    MASProductionPromotionRequirement.ControlSpecificProductionGapClosure
                },
                blockerSummary)
        End Function

        Private Shared Function CreateHostingControlRule(componentId As String,
                                                        displayName As String,
                                                        blockerSummary As String) As MASProductionPromotionRuleRecord
            Return New MASProductionPromotionRuleRecord(
                componentId,
                displayName,
                New MASProductionPromotionRequirement() {
                    MASProductionPromotionRequirement.ArchitectureRegistration,
                    MASProductionPromotionRequirement.PublicAddGateway,
                    MASProductionPromotionRequirement.RelationCoverage,
                    MASProductionPromotionRequirement.DedicatedRenderCoverage,
                    MASProductionPromotionRequirement.DataSourceOrHostingContract,
                    MASProductionPromotionRequirement.VirtualizationOrBoundedLayoutProof,
                    MASProductionPromotionRequirement.PersistenceContract,
                    MASProductionPromotionRequirement.PerformanceProof,
                    MASProductionPromotionRequirement.PublicAdapterPolicy,
                    MASProductionPromotionRequirement.DocumentationAndSamples,
                    MASProductionPromotionRequirement.MeasuredRuntimeBenchmark,
                    MASProductionPromotionRequirement.BenchmarkBaselineThresholdPolicy,
                    MASProductionPromotionRequirement.KeyboardAccessibilityStressProof,
                    MASProductionPromotionRequirement.RuntimeFaultStrictMode,
                    MASProductionPromotionRequirement.TimeMotionOwnership,
                    MASProductionPromotionRequirement.ControlSpecificProductionGapClosure,
                    MASProductionPromotionRequirement.HostingContractClosure,
                    MASProductionPromotionRequirement.RoutingShellBoundaryClosure,
                    MASProductionPromotionRequirement.ProviderHostAdoptionClosure,
                    MASProductionPromotionRequirement.DashboardResizeHostSampleClosure
                },
                blockerSummary)
        End Function

    End Class

End Namespace
