Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Final component-wide coverage audit for Nexamas UI broad surface materials. The source
    ''' test suite enforces the same rule with a real source scan: Component code may use the
    ''' semantic component gateway, primitives, or frame painter, but must not know low-level
    ''' consumer-kind/slot/role/runtime-material plumbing. Interactive control bodies may
    ''' consume material through the gateway; hover/pressed/selection overlays stay in Interaction.
    ''' </summary>
    Friend NotInheritable Class MASVisualSurfaceMaterialCoverageAudit
        Private Sub New()
        End Sub

        Friend Shared Function BuildCurrentSurfaceMaterialCoverage() As MASVisualSurfaceMaterialCoverageReport
            Dim publicGatewayManifest As MASPublicSurfaceMaterialGatewayManifest = MASPublicSurfaceMaterialGatewayManifest.CreateCurrent()

            Dim hasComponentGateway As Boolean = publicGatewayManifest IsNot Nothing AndAlso
                                                 publicGatewayManifest.HasLimitedPublicSurfaceMaterialGateways AndAlso
                                                 publicGatewayManifest.ReadyGatewayCount = publicGatewayManifest.EntryCount
            Dim hasNoLowLevelComponentRouteLeaks As Boolean = MASSurfaceTreatmentConsumerCatalog.CurrentOwnershipConsumerCount =
                                                              MASSurfaceTreatmentConsumerCatalog.RuntimeSurfaceVisualConsumerCount AndAlso
                                                              MASSurfaceTreatmentConsumerCatalog.InteractiveControlsAreOutOfScope
            Dim hasCentralRouteCoverage As Boolean = CentralRoutes().Count >= 10 AndAlso
                                                     MASSurfaceTreatmentConsumerCatalog.RuntimeSurfaceVisualConsumerCount >= 10
            Dim hasComponentSurfaceCoverage As Boolean = ComponentSurfaceOwners().Count >= 70
            Dim interactiveChromeStaysOutOfMaterialScope As Boolean = MASSurfaceTreatmentConsumerCatalog.InteractiveControlsAreOutOfScope

            Dim status As MASVisualSurfaceMaterialCoverageStatus = DetermineStatus(
                hasComponentGateway,
                hasNoLowLevelComponentRouteLeaks,
                hasCentralRouteCoverage,
                hasComponentSurfaceCoverage,
                interactiveChromeStaysOutOfMaterialScope)

            Return New MASVisualSurfaceMaterialCoverageReport(
                name:="Nexamas UI Surface Material Coverage",
                status:=status,
                hasComponentGateway:=hasComponentGateway,
                hasNoLowLevelComponentRouteLeaks:=hasNoLowLevelComponentRouteLeaks,
                hasCentralRouteCoverage:=hasCentralRouteCoverage,
                hasComponentSurfaceCoverage:=hasComponentSurfaceCoverage,
                interactiveChromeStaysOutOfMaterialScope:=interactiveChromeStaysOutOfMaterialScope,
                centralRoutes:=CentralRoutes(),
                componentSurfaceOwners:=ComponentSurfaceOwners(),
                outOfMaterialScopeBuckets:=OutOfMaterialScopeBuckets())
        End Function

        Private Shared Function DetermineStatus(hasComponentGateway As Boolean,
                                                hasNoLowLevelComponentRouteLeaks As Boolean,
                                                hasCentralRouteCoverage As Boolean,
                                                hasComponentSurfaceCoverage As Boolean,
                                                interactiveChromeStaysOutOfMaterialScope As Boolean) As MASVisualSurfaceMaterialCoverageStatus
            If Not hasComponentGateway Then Return MASVisualSurfaceMaterialCoverageStatus.BlockedByMissingComponentGateway
            If Not hasNoLowLevelComponentRouteLeaks Then Return MASVisualSurfaceMaterialCoverageStatus.BlockedByLowLevelComponentRouteLeak
            If Not hasCentralRouteCoverage Then Return MASVisualSurfaceMaterialCoverageStatus.BlockedByIncompleteCentralRouteCoverage
            If Not hasComponentSurfaceCoverage Then Return MASVisualSurfaceMaterialCoverageStatus.BlockedByIncompleteComponentSurfaceCoverage
            If Not interactiveChromeStaysOutOfMaterialScope Then Return MASVisualSurfaceMaterialCoverageStatus.BlockedByInteractiveScopeLeak
            Return MASVisualSurfaceMaterialCoverageStatus.Closed
        End Function

        Private Shared Function CentralRoutes() As IReadOnlyList(Of String)
            Return New ReadOnlyCollection(Of String)(New List(Of String) From {
                "MASSurfaceMaterialComponentGateway.TryDrawCardRootSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawCardViewportSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawControlBodySurface",
                "MASSurfaceMaterialComponentGateway.TryDrawActionChromeMaterialBody",
                "MASSurfaceMaterialComponentGateway.TryDrawInputFieldMaterialBody",
                "MASSurfaceMaterialComponentGateway.TryDrawSelectorChromeMaterialBody",
                "MASSurfaceMaterialComponentGateway.TryDrawBackgroundSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawMediaStageSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawToolbarSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawTopBarSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawPanelShellSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawPopupSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawGroupBoxSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawFloatingTooltipSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawFloatingToastSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawProgressSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawComposedCardSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawComposedCardRootSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawComposedCardViewportSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawComposedToolbarSurface",
                "MASSurfaceMaterialComponentGateway.TryDrawComposedMediaStageSurface",
                "MASVisualPrimitivesPainter.DrawCardSurface",
                "MASVisualPrimitivesPainter.DrawAcrylicSurface",
                "MASSurfaceFramePainter.TryDrawSwitchableViewportCardSurface",
                "MASSurfaceFramePainter.TryDrawSwitchableFloatingPopupSurface",
                "MASSurfaceFramePainter.TryDrawSwitchableFloatingToastSurface"
            })
        End Function

        Private Shared Function ComponentSurfaceOwners() As IReadOnlyList(Of String)
            Return New ReadOnlyCollection(Of String)(New List(Of String) From {
                "MASBackground", "MASCard", "MASPanelShell", "MASPanelShellDialog", "MASGroupBox",
                "MASExpander", "MASAccordion", "MASAppLayout", "MASSplitView", "MASSidePanel",
                "MASDrawer", "MASTopBar", "MASToolbar", "MASMenuBar", "MASMenuButton",
                "DropDownMenu", "MASContextMenu", "MASCommandPalette", "MASNavigationRail", "MASBreadcrumb",
                "MASPagination", "MASContentCarousel", "MASFileExplorer", "MASFilePicker", "MASFileDropZone",
                "MASListBox", "MASListView", "MASTreeRenderer", "MASDropDownListFloatContent", "MASComboBox",
                "MASDropDownList", "MASTextBox", "MASDatePicker", "MASTimePicker", "MASDateRangePicker",
                "MASCalendarView", "MASColorPicker", "MASTagInput", "MASDataForm", "MASPropertyGrid",
                "MASDataGrid", "MASDataView", "MASTreeGrid", "MASPivotTable", "MASAgendaView",
                "MASDashboardGrid", "MASMetricCard", "MASFilterBuilder", "MASAppliedFiltersBar", "MASKanbanBoard",
                "MASMasterDetailView", "MASChartLegend", "MASChart", "MASEmptyState", "MASFormValidationSummary",
                "MASNotificationPanel", "MASToast", "MASTooltip", "MASCallout", "MASStatusBanner",
                "MASLoadingSkeleton", "MASProgressBar", "MASOperationProgressBox", "MASImageViewer", "MASWizard",
                "MASStepper", "MASTransferList", "MASRating", "MASAvatarGroup", "MASBadge",
                "MASValidationMessage", "MASMessageBox", "MASTile", "MASTileBox", "MASSelector",
                "MASSegmentedControl", "MASTabStrip", "MASCheckBox", "MASRadioButton", "MASToggleSwitch",
                "MASSlider", "MASButton", "MASGlyphButton", "MASFlatActionButton", "MASSplitButton"
            })
        End Function

        Private Shared Function OutOfMaterialScopeBuckets() As IReadOnlyList(Of String)
            Return New ReadOnlyCollection(Of String)(New List(Of String) From {
                "glyph/icon drawing",
                "charts and plot primitives",
                "progress value fills",
                "button/input/selector hover pressed selected overlays",
                "row hover/pressed/selected overlays",
                "focus/interaction rings",
                "text selection/caret/editor chrome",
                "scrollbar rails/thumb interaction",
                "image/bitmap content and media pixels",
                "placeholder skeleton strips inside a material surface"
            })
        End Function
    End Class

End Namespace
