Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Quality

    ''' <summary>
    ''' Aggregate report for friend-only product-control keyboard/accessibility stress evidence.
    ''' </summary>
    Friend NotInheritable Class MASKeyboardAccessibilityStressReport

        Private Const ExpectedProductControlCount As Integer = 8
        Private ReadOnly _records As IReadOnlyList(Of MASKeyboardAccessibilityStressRecord)

        Friend Sub New(records As IEnumerable(Of MASKeyboardAccessibilityStressRecord))
            Dim normalized As New List(Of MASKeyboardAccessibilityStressRecord)()
            If records IsNot Nothing Then
                For Each record As MASKeyboardAccessibilityStressRecord In records
                    If record IsNot Nothing Then normalized.Add(record)
                Next
            End If
            _records = New ReadOnlyCollection(Of MASKeyboardAccessibilityStressRecord)(normalized.ToArray())
        End Sub

        Friend ReadOnly Property Records As IReadOnlyList(Of MASKeyboardAccessibilityStressRecord)
            Get
                Return _records
            End Get
        End Property

        Friend ReadOnly Property Count As Integer
            Get
                Return _records.Count
            End Get
        End Property

        Friend ReadOnly Property PassingCount As Integer
            Get
                Dim countValue As Integer = 0
                For Each record As MASKeyboardAccessibilityStressRecord In _records
                    If record IsNot Nothing AndAlso record.Passed Then countValue += 1
                Next
                Return countValue
            End Get
        End Property

        Friend ReadOnly Property ReadyForCommercialEvidence As Boolean
            Get
                If Count <> ExpectedProductControlCount Then Return False
                If FindById("treegrid") Is Nothing Then Return False
                If FindById("pivottable") Is Nothing Then Return False
                If FindById("kanban") Is Nothing Then Return False
                If FindById("agenda") Is Nothing Then Return False
                If FindById("dashboardgrid") Is Nothing Then Return False
                If FindById("masterdetail") Is Nothing Then Return False
                If FindById("applayout") Is Nothing Then Return False
                If FindById("splitview") Is Nothing Then Return False
                Return PassingCount = ExpectedProductControlCount
            End Get
        End Property

        Friend Function FindById(componentId As String) As MASKeyboardAccessibilityStressRecord
            Dim normalized As String = If(componentId, String.Empty).Trim()
            If normalized.Length = 0 Then Return Nothing

            For Each record As MASKeyboardAccessibilityStressRecord In _records
                If record IsNot Nothing AndAlso String.Equals(record.ComponentId, normalized, System.StringComparison.OrdinalIgnoreCase) Then
                    Return record
                End If
            Next

            Return Nothing
        End Function

    End Class

End Namespace
