Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.Virtualization

    ''' <summary>
    ''' VIRT-04 runtime proof report. It separates source/data projection scale from render/window virtualization by recording
    ''' 100k DataView filter/sort/group and 100k TreeView expand/flatten evidence without constructing a renderer, DataGrid,
    ''' realization plan, viewport, or shared virtualization controller.
    ''' </summary>
    Friend NotInheritable Class MASVirtualizationProjectionScaleReport
        Private ReadOnly _findings As IReadOnlyList(Of MASVirtualizationReadinessFinding)

        Friend Sub New(logicalItemCount As Integer,
                       dataViewFilteredRowCount As Integer,
                       dataViewSortedFirstId As Integer,
                       dataViewSortedLastId As Integer,
                       dataViewProjectedRowCount As Integer,
                       dataViewGroupCount As Integer,
                       treeCollapsedVisibleCount As Integer,
                       treeExpandedVisibleCount As Integer,
                       treeExpandToggleCount As Integer,
                       renderWindowDependencyCount As Integer,
                       findings As IEnumerable(Of MASVirtualizationReadinessFinding))
            Me.LogicalItemCount = Math.Max(0, logicalItemCount)
            Me.DataViewFilteredRowCount = Math.Max(0, dataViewFilteredRowCount)
            Me.DataViewSortedFirstId = dataViewSortedFirstId
            Me.DataViewSortedLastId = dataViewSortedLastId
            Me.DataViewProjectedRowCount = Math.Max(0, dataViewProjectedRowCount)
            Me.DataViewGroupCount = Math.Max(0, dataViewGroupCount)
            Me.TreeCollapsedVisibleCount = Math.Max(0, treeCollapsedVisibleCount)
            Me.TreeExpandedVisibleCount = Math.Max(0, treeExpandedVisibleCount)
            Me.TreeExpandToggleCount = Math.Max(0, treeExpandToggleCount)
            Me.RenderWindowDependencyCount = Math.Max(0, renderWindowDependencyCount)
            _findings = New ReadOnlyCollection(Of MASVirtualizationReadinessFinding)(If(findings, Enumerable.Empty(Of MASVirtualizationReadinessFinding)()).Where(Function(finding) finding IsNot Nothing).ToArray())
        End Sub

        Friend ReadOnly Property LogicalItemCount As Integer
        Friend ReadOnly Property DataViewFilteredRowCount As Integer
        Friend ReadOnly Property DataViewSortedFirstId As Integer
        Friend ReadOnly Property DataViewSortedLastId As Integer
        Friend ReadOnly Property DataViewProjectedRowCount As Integer
        Friend ReadOnly Property DataViewGroupCount As Integer
        Friend ReadOnly Property TreeCollapsedVisibleCount As Integer
        Friend ReadOnly Property TreeExpandedVisibleCount As Integer
        Friend ReadOnly Property TreeExpandToggleCount As Integer
        Friend ReadOnly Property RenderWindowDependencyCount As Integer

        Friend ReadOnly Property Findings As IReadOnlyList(Of MASVirtualizationReadinessFinding)
            Get
                Return _findings
            End Get
        End Property

        Friend ReadOnly Property HasFindings As Boolean
            Get
                Return _findings.Count > 0
            End Get
        End Property

        Friend ReadOnly Property NoRenderWindowDependency As Boolean
            Get
                Return RenderWindowDependencyCount = 0
            End Get
        End Property

        Friend ReadOnly Property Proves100kDataViewFilterSortGroupIndependentFromRender As Boolean
            Get
                Return LogicalItemCount >= MASVirtualizationProjectionScaleGate.RequiredLogicalItemCount AndAlso
                       DataViewFilteredRowCount > 0 AndAlso
                       DataViewFilteredRowCount < LogicalItemCount AndAlso
                       DataViewSortedFirstId <= DataViewSortedLastId AndAlso
                       DataViewProjectedRowCount >= MASVirtualizationProjectionScaleGate.RequiredLogicalItemCount AndAlso
                       DataViewGroupCount >= MASVirtualizationProjectionScaleGate.RequiredDataViewGroupCount AndAlso
                       NoRenderWindowDependency
            End Get
        End Property

        Friend ReadOnly Property Proves100kTreeExpandIndependentFromRender As Boolean
            Get
                Return LogicalItemCount >= MASVirtualizationProjectionScaleGate.RequiredLogicalItemCount AndAlso
                       TreeCollapsedVisibleCount = MASVirtualizationProjectionScaleGate.RequiredTreeRootCount AndAlso
                       TreeExpandedVisibleCount >= MASVirtualizationProjectionScaleGate.RequiredLogicalItemCount AndAlso
                       TreeExpandToggleCount >= MASVirtualizationProjectionScaleGate.RequiredTreeRootCount AndAlso
                       NoRenderWindowDependency
            End Get
        End Property

        Friend ReadOnly Property IsReady As Boolean
            Get
                Return Not HasFindings AndAlso
                       Proves100kDataViewFilterSortGroupIndependentFromRender AndAlso
                       Proves100kTreeExpandIndependentFromRender AndAlso
                       NoRenderWindowDependency
            End Get
        End Property

    End Class

End Namespace
