Option Strict On
Option Explicit On

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

Namespace Nexamas.UI.PropertyGrid

    ''' <summary>
    ''' Internal read snapshot used by governance and tests without touching a live control tree.
    ''' </summary>
    Friend NotInheritable Class MASPropertyGridSnapshot

        Private ReadOnly _properties As IReadOnlyList(Of MASPropertyGridPropertyState)

        Friend Sub New(properties As IEnumerable(Of MASPropertyGridPropertyState))
            Dim list As New List(Of MASPropertyGridPropertyState)()
            If properties IsNot Nothing Then
                For Each item As MASPropertyGridPropertyState In properties
                    If item IsNot Nothing Then list.Add(item)
                Next
            End If

            _properties = New ReadOnlyCollection(Of MASPropertyGridPropertyState)(list)
        End Sub

        Friend ReadOnly Property Properties As IReadOnlyList(Of MASPropertyGridPropertyState)
            Get
                Return _properties
            End Get
        End Property

        Friend ReadOnly Property PropertyCount As Integer
            Get
                Return _properties.Count
            End Get
        End Property

        Friend ReadOnly Property CategoryCount As Integer
            Get
                Return _properties.Select(Function(item) item.Category).Distinct(System.StringComparer.OrdinalIgnoreCase).Count()
            End Get
        End Property

        Friend ReadOnly Property EditablePropertyCount As Integer
            Get
                Return _properties.Where(Function(item) item.IsEditable).Count()
            End Get
        End Property

        Friend ReadOnly Property HasBooleanEditing As Boolean
            Get
                Return _properties.Any(Function(item) item.IsEditable AndAlso item.Kind = MASPropertyGridValueKind.BooleanValue)
            End Get
        End Property

        Friend ReadOnly Property HasTextEditing As Boolean
            Get
                Return _properties.Any(Function(item) item.IsEditable AndAlso item.Kind = MASPropertyGridValueKind.Text)
            End Get
        End Property

        Friend ReadOnly Property ReadyForObjectPropertyEditing As Boolean
            Get
                Return PropertyCount > 0 AndAlso EditablePropertyCount > 0 AndAlso CategoryCount > 0
            End Get
        End Property

    End Class

End Namespace
