Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Verification

    ''' <summary>
    ''' Descriptor-level dashboard read model for Render Verification coverage.
    ''' </summary>
    Friend NotInheritable Class MASRenderVerificationElementCoverageReport
        Private ReadOnly _entries As IReadOnlyList(Of MASRenderVerificationElementCoverageEntry)

        Friend Sub New(entries As IEnumerable(Of MASRenderVerificationElementCoverageEntry),
                       graphReport As MASRenderVerificationCoverageReport)
            Dim normalized As New List(Of MASRenderVerificationElementCoverageEntry)()
            If entries IsNot Nothing Then
                For Each entry As MASRenderVerificationElementCoverageEntry In entries
                    If entry IsNot Nothing Then normalized.Add(entry)
                Next
            End If

            _entries = New ReadOnlyCollection(Of MASRenderVerificationElementCoverageEntry)(normalized)
            Me.GraphReport = graphReport
        End Sub

        Friend ReadOnly Property Entries As IReadOnlyList(Of MASRenderVerificationElementCoverageEntry)
            Get
                Return _entries
            End Get
        End Property

        Friend ReadOnly Property GraphReport As MASRenderVerificationCoverageReport

        Friend ReadOnly Property ComponentCount As Integer
            Get
                Return _entries.Count
            End Get
        End Property

        Friend ReadOnly Property MatchedCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.Matched)
            End Get
        End Property

        Friend ReadOnly Property VisualReviewCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.VisualReview)
            End Get
        End Property

        Friend ReadOnly Property ChangedCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.Changed)
            End Get
        End Property

        Friend ReadOnly Property InvalidCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.Invalid)
            End Get
        End Property

        Friend ReadOnly Property MissingSnapshotCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.MissingSnapshot)
            End Get
        End Property

        Friend ReadOnly Property ContractProofCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.ContractProof)
            End Get
        End Property

        Friend ReadOnly Property UnclassifiedCount As Integer
            Get
                Return CountState(MASRenderVerificationElementCoverageState.Unclassified)
            End Get
        End Property

        Friend ReadOnly Property BlockingCount As Integer
            Get
                Dim count As Integer = 0
                For Each entry As MASRenderVerificationElementCoverageEntry In _entries
                    If entry IsNot Nothing AndAlso entry.IsBlocking Then count += 1
                Next
                Return count
            End Get
        End Property

        Friend ReadOnly Property Summary As String
            Get
                Return ComponentCount.ToString(CultureInfo.InvariantCulture) & " component descriptor(s), " &
                       MatchedCount.ToString(CultureInfo.InvariantCulture) & " matched visual row(s), " &
                       VisualReviewCount.ToString(CultureInfo.InvariantCulture) & " review row(s), " &
                       ChangedCount.ToString(CultureInfo.InvariantCulture) & " changed row(s), " &
                       MissingSnapshotCount.ToString(CultureInfo.InvariantCulture) & " missing snapshot row(s), " &
                       ContractProofCount.ToString(CultureInfo.InvariantCulture) & " contract/system proof row(s), " &
                       UnclassifiedCount.ToString(CultureInfo.InvariantCulture) & " unclassified row(s)."
            End Get
        End Property

        Private Function CountState(state As MASRenderVerificationElementCoverageState) As Integer
            Dim count As Integer = 0
            For Each entry As MASRenderVerificationElementCoverageEntry In _entries
                If entry IsNot Nothing AndAlso entry.State = state Then count += 1
            Next
            Return count
        End Function

    End Class

End Namespace
