Option Strict On
Option Explicit On

Imports System.Collections.Generic

Namespace Nexamas.UI.Rendering

    Friend NotInheritable Class MASSurfaceTreatmentRuntimeSurfaceVisualApplicationBuilder
        Private Sub New()
        End Sub

        Friend Shared Function BuildRuntimeSurfaceVisualApplicationReadiness() As MASSurfaceTreatmentRuntimeSurfaceVisualApplicationReport
            Dim entries As New List(Of MASSurfaceTreatmentRuntimeSurfaceVisualApplicationEntry)()

            For Each consumerKind As MASSurfaceTreatmentConsumerKind In MASSurfaceTreatmentConsumerCatalog.RuntimeSurfaceVisualConsumers()
                Add(entries,
                    consumerKind,
                    MASSurfaceTreatmentConsumerCatalog.ConsumerDisplayName(consumerKind),
                    MASSurfaceTreatmentConsumerCatalog.IsPublicSurfaceGateway(consumerKind))
            Next

            Return New MASSurfaceTreatmentRuntimeSurfaceVisualApplicationReport(
                name:="Surface Treatment Runtime Surface Visual Application Readiness",
                entries:=entries.ToArray())
        End Function

        Private Shared Sub Add(entries As List(Of MASSurfaceTreatmentRuntimeSurfaceVisualApplicationEntry),
                               consumerKind As MASSurfaceTreatmentConsumerKind,
                               consumerName As String,
                               isPublicSurfaceGateway As Boolean)
            If entries Is Nothing Then Return

            Dim example As String = "crystal"
            Dim resolved As String = MASSurfaceTreatmentRuntimeSurfaceVisual.ResolveRuntimeMaterialKey(consumerKind, example)
            Dim resolverReady As Boolean = String.Equals(resolved, MASSurfaceMaterialIds.CrystalIce, System.StringComparison.OrdinalIgnoreCase)
            Dim registryReady As Boolean = MASSurfaceMaterialRegistry.Contains(resolved)
            Dim runtimeSurface As Boolean = MASSurfaceTreatmentRuntimeSurfaceVisual.IsSurfaceVisualConsumer(consumerKind)
            Dim excludesInteractiveControls As Boolean = MASSurfaceTreatmentConsumerCatalog.ExcludesInteractiveControlConsumer(consumerKind)
            Dim status As MASSurfaceTreatmentRuntimeSurfaceVisualApplicationStatus

            If Not excludesInteractiveControls Then
                status = MASSurfaceTreatmentRuntimeSurfaceVisualApplicationStatus.BlockedByInteractiveControlScope
            ElseIf Not runtimeSurface Then
                status = MASSurfaceTreatmentRuntimeSurfaceVisualApplicationStatus.BlockedByUnsupportedConsumer
            ElseIf Not resolverReady OrElse Not registryReady Then
                status = MASSurfaceTreatmentRuntimeSurfaceVisualApplicationStatus.BlockedByIncompleteResolver
            Else
                status = MASSurfaceTreatmentRuntimeSurfaceVisualApplicationStatus.ReadyForSurfaceVisualMaterialSelection
            End If

            entries.Add(New MASSurfaceTreatmentRuntimeSurfaceVisualApplicationEntry(
                consumerKind:=consumerKind,
                consumerName:=consumerName,
                status:=status,
                defaultMaterialKey:=MASSurfaceMaterialIds.Auto,
                exampleMaterialKey:=example,
                resolvedExampleMaterialKey:=resolved,
                preservesDefaultVisualWithAuto:=True,
                usesOfficialResolver:=resolverReady,
                usesOfficialMaterialRegistry:=registryReady,
                isPublicSurfaceGateway:=isPublicSurfaceGateway,
                excludesInteractiveControls:=excludesInteractiveControls,
                notes:="Auto preserves the existing visual path. Explicit material keys resolve through Surface Treatment resolver and the official material registry."))
        End Sub

    End Class

End Namespace
