Imports System.Collections.Generic
Imports System.Linq

Namespace Nexamas.UI.Verification

    ''' <summary>
    ''' Describes one deterministic screenshot-diff scenario: component identity, state, theme, DPI, and pixel size.
    ''' The scenario is immutable after construction so baseline file names and CI reports stay stable over time.
    ''' </summary>
    Friend NotInheritable Class MASRenderVerificationScenario

        Private ReadOnly _tags As IReadOnlyList(Of String)

        Friend Sub New(id As String,
                       componentKey As String,
                       displayName As String,
                       stateKey As String,
                       themeKey As String,
                       dpiScale As Single,
                       widthPx As Integer,
                       heightPx As Integer,
                       Optional tags As IEnumerable(Of String) = Nothing)
            Me.Id = If(id, String.Empty).Trim()
            Me.ComponentKey = If(componentKey, String.Empty).Trim()
            Me.DisplayName = If(displayName, String.Empty).Trim()
            Me.StateKey = If(stateKey, String.Empty).Trim()
            Me.ThemeKey = If(themeKey, String.Empty).Trim()
            Me.DpiScale = dpiScale
            Me.WidthPx = widthPx
            Me.HeightPx = heightPx

            If tags Is Nothing Then
                _tags = Array.Empty(Of String)()
            Else
                _tags = tags.
                    Where(Function(tag) Not String.IsNullOrWhiteSpace(tag)).
                    Select(Function(tag) tag.Trim()).
                    Distinct(StringComparer.OrdinalIgnoreCase).
                    ToArray()
            End If
        End Sub

        Friend ReadOnly Property Id As String
        Friend ReadOnly Property ComponentKey As String
        Friend ReadOnly Property DisplayName As String
        Friend ReadOnly Property StateKey As String
        Friend ReadOnly Property ThemeKey As String
        Friend ReadOnly Property DpiScale As Single
        Friend ReadOnly Property WidthPx As Integer
        Friend ReadOnly Property HeightPx As Integer

        Friend ReadOnly Property Tags As IReadOnlyList(Of String)
            Get
                Return _tags
            End Get
        End Property

        Friend ReadOnly Property IsValid As Boolean
            Get
                Return Not String.IsNullOrWhiteSpace(Id) AndAlso
                       Not String.IsNullOrWhiteSpace(ComponentKey) AndAlso
                       Not String.IsNullOrWhiteSpace(StateKey) AndAlso
                       Not String.IsNullOrWhiteSpace(ThemeKey) AndAlso
                       DpiScale > 0.0F AndAlso
                       WidthPx > 0 AndAlso
                       HeightPx > 0
            End Get
        End Property

        Public Overrides Function ToString() As String
            Return Id & " [" & ComponentKey & ", " & StateKey & ", " & ThemeKey & ", dpi=" & DpiScale.ToString(Globalization.CultureInfo.InvariantCulture) & "]"
        End Function

    End Class

End Namespace
