Option Strict On
Option Explicit On

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Evidence that broad surface consumers use the material slot route instead of bypassing
    ''' generic slot/profile resolution when applying explicit material keys.
    ''' </summary>
    Friend NotInheritable Class MASSurfaceMaterialAdoptionReport

        Friend Sub New(name As String,
                       status As MASSurfaceMaterialAdoptionStatus,
                       mappedConsumerCount As Integer,
                       expectedMappedConsumerCount As Integer,
                       hasConsumerSlotCatalog As Boolean,
                       hasExplicitSlotRuntimeGateway As Boolean,
                       componentBypassCount As Integer)
            Me.Name = Normalize(name, "Surface Material Adoption")
            Me.Status = status
            Me.MappedConsumerCount = If(mappedConsumerCount < 0, 0, mappedConsumerCount)
            Me.ExpectedMappedConsumerCount = If(expectedMappedConsumerCount < 0, 0, expectedMappedConsumerCount)
            Me.HasConsumerSlotCatalog = hasConsumerSlotCatalog
            Me.HasExplicitSlotRuntimeGateway = hasExplicitSlotRuntimeGateway
            Me.ComponentBypassCount = If(componentBypassCount < 0, 0, componentBypassCount)
        End Sub

        Friend ReadOnly Property Name As String
        Friend ReadOnly Property Status As MASSurfaceMaterialAdoptionStatus
        Friend ReadOnly Property MappedConsumerCount As Integer
        Friend ReadOnly Property ExpectedMappedConsumerCount As Integer
        Friend ReadOnly Property HasConsumerSlotCatalog As Boolean
        Friend ReadOnly Property HasExplicitSlotRuntimeGateway As Boolean
        Friend ReadOnly Property ComponentBypassCount As Integer

        Friend ReadOnly Property IsReady As Boolean
            Get
                Return Status = MASSurfaceMaterialAdoptionStatus.SlotAdoptionReady AndAlso
                       HasConsumerSlotCatalog AndAlso
                       HasExplicitSlotRuntimeGateway AndAlso
                       MappedConsumerCount >= ExpectedMappedConsumerCount AndAlso
                       ComponentBypassCount = 0
            End Get
        End Property

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

    End Class

End Namespace
