Option Strict On
Option Explicit On

Imports System
Imports System.Collections.Generic

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Public read-only diagnostics snapshot for SDK consumers.
    ''' </summary>
    ''' <remarks>
    ''' Counts are derived from the currently retained in-process fault window. Long-running
    ''' retention counters are intentionally separate from this safe gateway and are governed by
    ''' the fault-storm retention gate.
    ''' </remarks>
    Public NotInheritable Class MASApplicationDiagnosticsSnapshot

        Friend Sub New(capturedUtc As DateTimeOffset,
                       retainedFaultCount As Integer,
                       recentFaults As IReadOnlyList(Of MASApplicationDiagnosticsFaultSummary),
                       recoverableCount As Integer,
                       boundaryFailureCount As Integer,
                       criticalStateTransitionCount As Integer,
                       diagnosticOnlyCount As Integer,
                       renderFallbackCount As Integer,
                       inputBoundaryCount As Integer,
                       disposeCleanupCount As Integer,
                       lifecycleBreakingCount As Integer,
                       nativeInteropCount As Integer,
                       fileSystemBoundaryCount As Integer,
                       clipboardBoundaryCount As Integer,
                       textShapingFallbackCount As Integer,
                       diagnosticsDiskLoggingEnabled As Boolean,
                       throwOnSwallowedException As Boolean,
                       throwOnLifecycleBreakingException As Boolean,
                       traceRepeatedBoundaryExceptions As Boolean)

            Me.CapturedUtc = capturedUtc
            Me.RetainedFaultCount = Math.Max(0, retainedFaultCount)
            If recentFaults Is Nothing Then
                Me.RecentFaults = Array.Empty(Of MASApplicationDiagnosticsFaultSummary)()
            Else
                Me.RecentFaults = recentFaults
            End If
            Me.RecoverableCount = Math.Max(0, recoverableCount)
            Me.BoundaryFailureCount = Math.Max(0, boundaryFailureCount)
            Me.CriticalStateTransitionCount = Math.Max(0, criticalStateTransitionCount)
            Me.DiagnosticOnlyCount = Math.Max(0, diagnosticOnlyCount)
            Me.RenderFallbackCount = Math.Max(0, renderFallbackCount)
            Me.InputBoundaryCount = Math.Max(0, inputBoundaryCount)
            Me.DisposeCleanupCount = Math.Max(0, disposeCleanupCount)
            Me.LifecycleBreakingCount = Math.Max(0, lifecycleBreakingCount)
            Me.NativeInteropCount = Math.Max(0, nativeInteropCount)
            Me.FileSystemBoundaryCount = Math.Max(0, fileSystemBoundaryCount)
            Me.ClipboardBoundaryCount = Math.Max(0, clipboardBoundaryCount)
            Me.TextShapingFallbackCount = Math.Max(0, textShapingFallbackCount)
            Me.DiagnosticsDiskLoggingEnabled = diagnosticsDiskLoggingEnabled
            Me.ThrowOnSwallowedException = throwOnSwallowedException
            Me.ThrowOnLifecycleBreakingException = throwOnLifecycleBreakingException
            Me.TraceRepeatedBoundaryExceptions = traceRepeatedBoundaryExceptions
        End Sub

        Public ReadOnly Property CapturedUtc As DateTimeOffset
        Public ReadOnly Property RetainedFaultCount As Integer
        Public ReadOnly Property RecentFaults As IReadOnlyList(Of MASApplicationDiagnosticsFaultSummary)
        Public ReadOnly Property RecoverableCount As Integer
        Public ReadOnly Property BoundaryFailureCount As Integer
        Public ReadOnly Property CriticalStateTransitionCount As Integer
        Public ReadOnly Property DiagnosticOnlyCount As Integer
        Public ReadOnly Property RenderFallbackCount As Integer
        Public ReadOnly Property InputBoundaryCount As Integer
        Public ReadOnly Property DisposeCleanupCount As Integer
        Public ReadOnly Property LifecycleBreakingCount As Integer
        Public ReadOnly Property NativeInteropCount As Integer
        Public ReadOnly Property FileSystemBoundaryCount As Integer
        Public ReadOnly Property ClipboardBoundaryCount As Integer
        Public ReadOnly Property TextShapingFallbackCount As Integer
        Public ReadOnly Property DiagnosticsDiskLoggingEnabled As Boolean
        Public ReadOnly Property ThrowOnSwallowedException As Boolean
        Public ReadOnly Property ThrowOnLifecycleBreakingException As Boolean
        Public ReadOnly Property TraceRepeatedBoundaryExceptions As Boolean

        Public ReadOnly Property HasFaults As Boolean
            Get
                Return RetainedFaultCount > 0
            End Get
        End Property

        Public ReadOnly Property MostRecentFault As MASApplicationDiagnosticsFaultSummary
            Get
                If RecentFaults Is Nothing OrElse RecentFaults.Count = 0 Then Return Nothing
                Return RecentFaults(RecentFaults.Count - 1)
            End Get
        End Property

        Public ReadOnly Property IsReadOnlySnapshot As Boolean
            Get
                Return True
            End Get
        End Property

    End Class

End Namespace
