Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Friend-only evidence that broad Nexamas UI surfaces can be switched from one internal
    ''' material/profile selection point while the default state remains visually inert.
    ''' </summary>
    Friend NotInheritable Class MASVisualSurfaceMaterialSwitchReadinessReport
        Private ReadOnly _switchableSurfaceFamilies As IReadOnlyList(Of String)
        Private ReadOnly _frameBackedSwitchConsumers As IReadOnlyList(Of String)

        Friend Sub New(name As String,
                       status As MASVisualSurfaceMaterialSwitchReadinessStatus,
                       hasRuntimeSwitchGateway As Boolean,
                       defaultStateIsInert As Boolean,
                       slotResolverUsesRuntimeSwitch As Boolean,
                       runtimeSurfaceUsesRuntimeSwitch As Boolean,
                       frameBackedSurfacesUseRuntimeSwitchWhenActive As Boolean,
                       explicitMaterialOverridesStayExplicit As Boolean,
                       switchableSurfaceFamilies As IEnumerable(Of String),
                       frameBackedSwitchConsumers As IEnumerable(Of String))
            Me.Name = Normalize(name, "Nexamas UI Surface Material Switch Readiness")
            Me.Status = status
            Me.HasRuntimeSwitchGateway = hasRuntimeSwitchGateway
            Me.DefaultStateIsInert = defaultStateIsInert
            Me.SlotResolverUsesRuntimeSwitch = slotResolverUsesRuntimeSwitch
            Me.RuntimeSurfaceUsesRuntimeSwitch = runtimeSurfaceUsesRuntimeSwitch
            Me.FrameBackedSurfacesUseRuntimeSwitchWhenActive = frameBackedSurfacesUseRuntimeSwitchWhenActive
            Me.ExplicitMaterialOverridesStayExplicit = explicitMaterialOverridesStayExplicit
            _switchableSurfaceFamilies = New ReadOnlyCollection(Of String)(NormalizeList(switchableSurfaceFamilies))
            _frameBackedSwitchConsumers = New ReadOnlyCollection(Of String)(NormalizeList(frameBackedSwitchConsumers))
            Me.SwitchableSurfaceFamilyCount = _switchableSurfaceFamilies.Count
            Me.FrameBackedSwitchConsumerCount = _frameBackedSwitchConsumers.Count
            Me.IsClosed = Status = MASVisualSurfaceMaterialSwitchReadinessStatus.Closed AndAlso
                          HasRuntimeSwitchGateway AndAlso
                          DefaultStateIsInert AndAlso
                          SlotResolverUsesRuntimeSwitch AndAlso
                          RuntimeSurfaceUsesRuntimeSwitch AndAlso
                          FrameBackedSurfacesUseRuntimeSwitchWhenActive AndAlso
                          ExplicitMaterialOverridesStayExplicit AndAlso
                          SwitchableSurfaceFamilyCount >= 5 AndAlso
                          FrameBackedSwitchConsumerCount >= 6
        End Sub

        Friend ReadOnly Property Name As String
        Friend ReadOnly Property Status As MASVisualSurfaceMaterialSwitchReadinessStatus
        Friend ReadOnly Property HasRuntimeSwitchGateway As Boolean
        Friend ReadOnly Property DefaultStateIsInert As Boolean
        Friend ReadOnly Property SlotResolverUsesRuntimeSwitch As Boolean
        Friend ReadOnly Property RuntimeSurfaceUsesRuntimeSwitch As Boolean
        Friend ReadOnly Property FrameBackedSurfacesUseRuntimeSwitchWhenActive As Boolean
        Friend ReadOnly Property ExplicitMaterialOverridesStayExplicit As Boolean
        Friend ReadOnly Property SwitchableSurfaceFamilyCount As Integer
        Friend ReadOnly Property FrameBackedSwitchConsumerCount As Integer
        Friend ReadOnly Property IsClosed As Boolean

        Friend ReadOnly Property SwitchableSurfaceFamilies As IReadOnlyList(Of String)
            Get
                Return _switchableSurfaceFamilies
            End Get
        End Property

        Friend ReadOnly Property FrameBackedSwitchConsumers As IReadOnlyList(Of String)
            Get
                Return _frameBackedSwitchConsumers
            End Get
        End Property

        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
                Dim normalized As String = Normalize(value, String.Empty)
                If normalized.Length > 0 AndAlso Not result.Contains(normalized) Then result.Add(normalized)
            Next

            Return result
        End Function

        Private Shared Function Normalize(value As String, fallback As String) As String
            Dim safe As String = If(value, String.Empty).Trim()
            If safe.Length = 0 Then Return If(fallback, String.Empty).Trim()
            Return safe
        End Function
    End Class

End Namespace
