Option Strict On
Option Explicit On

Imports System.Collections.Generic
Imports System.Linq

Namespace Nexamas.UI.Composition

    ''' <summary>
    ''' Collects diagnostics for a single layout operation.
    ''' It is passed through contexts and does not own host/control state.
    ''' </summary>
    <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
    Friend NotInheritable Class MASLayoutDiagnosticBag

        Private ReadOnly _items As New List(Of MASLayoutDiagnostic)()

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

        Friend ReadOnly Property HasErrors As Boolean
            Get
                Return _items.Any(Function(d) d IsNot Nothing AndAlso d.Severity = MASLayoutDiagnosticSeverity.Error)
            End Get
        End Property

        Friend Sub Add(diagnostic As MASLayoutDiagnostic)
            If diagnostic Is Nothing Then Return
            _items.Add(diagnostic)
        End Sub

        Friend Sub AddError(code As String, message As String, Optional detail As String = "")
            Add(MASLayoutDiagnostic.Error(code, message, detail))
        End Sub

        Friend Sub AddWarning(code As String, message As String, Optional detail As String = "")
            Add(MASLayoutDiagnostic.Warning(code, message, detail))
        End Sub

        Friend Function ToArray() As MASLayoutDiagnostic()
            Return _items.ToArray()
        End Function

    End Class

End Namespace
