Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Components

    Friend NotInheritable Class MASImageViewerSurfaceContractReport
        Private ReadOnly _evidence As IReadOnlyList(Of String)

        Friend Sub New(name As String,
                       status As MASImageViewerSurfaceContractStatus,
                       hasSurfacePolicy As Boolean,
                       hasMediaSurfaceProfile As Boolean,
                       hasRegionBindings As Boolean,
                       hasIndependentRegionMaterials As Boolean,
                       hasExpectedDefaultMaterialMap As Boolean,
                       hasOfficialMaterials As Boolean,
                       hasPanelShellRootProof As Boolean,
                       hasLayoutRegionProof As Boolean,
                       hasRenderRouteProof As Boolean,
                       hasNoLegacyMediaPainterPath As Boolean,
                       hasProfileSwitchProof As Boolean,
                       hasNoMediaShellLiteralInImageViewer As Boolean,
                       rootMaterialKey As String,
                       toolbarMaterialKey As String,
                       viewportMaterialKey As String,
                       footerMaterialKey As String,
                       overlayMaterialKey As String,
                       evidence As IEnumerable(Of String))
            Me.Name = Normalize(name, "MASImageViewer Surface Contract")
            Me.Status = status
            Me.HasSurfacePolicy = hasSurfacePolicy
            Me.HasMediaSurfaceProfile = hasMediaSurfaceProfile
            Me.HasRegionBindings = hasRegionBindings
            Me.HasIndependentRegionMaterials = hasIndependentRegionMaterials
            Me.HasExpectedDefaultMaterialMap = hasExpectedDefaultMaterialMap
            Me.HasOfficialMaterials = hasOfficialMaterials
            Me.HasPanelShellRootProof = hasPanelShellRootProof
            Me.HasLayoutRegionProof = hasLayoutRegionProof
            Me.HasRenderRouteProof = hasRenderRouteProof
            Me.HasNoLegacyMediaPainterPath = hasNoLegacyMediaPainterPath
            Me.HasProfileSwitchProof = hasProfileSwitchProof
            Me.HasNoMediaShellLiteralInImageViewer = hasNoMediaShellLiteralInImageViewer
            Me.RootMaterialKey = Normalize(rootMaterialKey, String.Empty)
            Me.ToolbarMaterialKey = Normalize(toolbarMaterialKey, String.Empty)
            Me.ViewportMaterialKey = Normalize(viewportMaterialKey, String.Empty)
            Me.FooterMaterialKey = Normalize(footerMaterialKey, String.Empty)
            Me.OverlayMaterialKey = Normalize(overlayMaterialKey, String.Empty)
            _evidence = New ReadOnlyCollection(Of String)(NormalizeList(evidence))
        End Sub

        Friend ReadOnly Property Name As String
        Friend ReadOnly Property Status As MASImageViewerSurfaceContractStatus
        Friend ReadOnly Property HasSurfacePolicy As Boolean
        Friend ReadOnly Property HasMediaSurfaceProfile As Boolean
        Friend ReadOnly Property HasRegionBindings As Boolean
        Friend ReadOnly Property HasIndependentRegionMaterials As Boolean
        Friend ReadOnly Property HasExpectedDefaultMaterialMap As Boolean
        Friend ReadOnly Property HasOfficialMaterials As Boolean
        Friend ReadOnly Property HasPanelShellRootProof As Boolean
        Friend ReadOnly Property HasLayoutRegionProof As Boolean
        Friend ReadOnly Property HasRenderRouteProof As Boolean
        Friend ReadOnly Property HasNoLegacyMediaPainterPath As Boolean
        Friend ReadOnly Property HasProfileSwitchProof As Boolean
        Friend ReadOnly Property HasNoMediaShellLiteralInImageViewer As Boolean
        Friend ReadOnly Property RootMaterialKey As String
        Friend ReadOnly Property ToolbarMaterialKey As String
        Friend ReadOnly Property ViewportMaterialKey As String
        Friend ReadOnly Property FooterMaterialKey As String
        Friend ReadOnly Property OverlayMaterialKey As String

        Friend ReadOnly Property Evidence As IReadOnlyList(Of String)
            Get
                Return _evidence
            End Get
        End Property

        Friend ReadOnly Property IsClosed As Boolean
            Get
                Return Status = MASImageViewerSurfaceContractStatus.Closed AndAlso
                       HasSurfacePolicy AndAlso
                       HasMediaSurfaceProfile AndAlso
                       HasRegionBindings AndAlso
                       HasIndependentRegionMaterials AndAlso
                       HasExpectedDefaultMaterialMap AndAlso
                       HasOfficialMaterials AndAlso
                       HasPanelShellRootProof AndAlso
                       HasLayoutRegionProof AndAlso
                       HasRenderRouteProof AndAlso
                       HasNoLegacyMediaPainterPath AndAlso
                       HasProfileSwitchProof AndAlso
                       HasNoMediaShellLiteralInImageViewer
            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 result As String = If(value, String.Empty).Trim()
            If result.Length = 0 Then Return fallback
            Return result
        End Function
    End Class

End Namespace
