Option Strict On
Option Explicit On

Imports System
Imports System.Runtime.CompilerServices
Imports Nexamas.UI.Diagnostics

Namespace Nexamas.UI.Virtualization

    ''' <summary>
    ''' Central helper for TileBox/DropDown virtualization consumer fallback boundaries.
    ''' </summary>
    ''' <remarks>
    ''' The helper records a structured diagnostic code before delegating to MASExceptionSilencer,
    ''' so normal builds keep fail-closed behavior while strict mode still throws from the official
    ''' silencer path. This prevents silent helper fallback without creating another exception policy.
    ''' </remarks>
    Friend NotInheritable Class MASVirtualizationConsumerFaultBoundary
        Private Sub New()
        End Sub

        Friend Shared Sub SwallowRenderFallback(ex As Exception,
                                                diagnosticCode As MASVirtualizationConsumerDiagnosticCode,
                                                consumerName As String,
                                                context As String,
                                                Optional reason As String = Nothing,
                                                <CallerMemberName> Optional memberName As String = Nothing,
                                                <CallerFilePath> Optional sourceFile As String = Nothing,
                                                <CallerLineNumber> Optional sourceLine As Integer = 0)
            RecordFailure(ex, diagnosticCode, consumerName, context, reason, MASExceptionSeverity.Recoverable, MASExceptionHandlingCategory.RenderFallback, memberName, sourceFile, sourceLine)
            MASExceptionSilencer.SwallowRenderFallback(ex, context:=context, memberName:=memberName, sourceFile:=sourceFile, sourceLine:=sourceLine)
        End Sub

        Friend Shared Sub SwallowInputBoundary(ex As Exception,
                                               diagnosticCode As MASVirtualizationConsumerDiagnosticCode,
                                               consumerName As String,
                                               context As String,
                                               Optional reason As String = Nothing,
                                               <CallerMemberName> Optional memberName As String = Nothing,
                                               <CallerFilePath> Optional sourceFile As String = Nothing,
                                               <CallerLineNumber> Optional sourceLine As Integer = 0)
            RecordFailure(ex, diagnosticCode, consumerName, context, reason, MASExceptionSeverity.BoundaryFailure, MASExceptionHandlingCategory.InputBoundary, memberName, sourceFile, sourceLine)
            MASExceptionSilencer.SwallowInputBoundary(ex, context:=context, memberName:=memberName, sourceFile:=sourceFile, sourceLine:=sourceLine)
        End Sub

        Friend Shared Sub SwallowRecoverable(ex As Exception,
                                             diagnosticCode As MASVirtualizationConsumerDiagnosticCode,
                                             consumerName As String,
                                             context As String,
                                             Optional reason As String = Nothing,
                                             <CallerMemberName> Optional memberName As String = Nothing,
                                             <CallerFilePath> Optional sourceFile As String = Nothing,
                                             <CallerLineNumber> Optional sourceLine As Integer = 0)
            RecordFailure(ex, diagnosticCode, consumerName, context, reason, MASExceptionSeverity.Recoverable, MASExceptionHandlingCategory.Recoverable, memberName, sourceFile, sourceLine)
            MASExceptionSilencer.SwallowRecoverable(ex, context:=context, memberName:=memberName, sourceFile:=sourceFile, sourceLine:=sourceLine)
        End Sub

        Private Shared Sub RecordFailure(ex As Exception,
                                         diagnosticCode As MASVirtualizationConsumerDiagnosticCode,
                                         consumerName As String,
                                         context As String,
                                         reason As String,
                                         severity As MASExceptionSeverity,
                                         category As MASExceptionHandlingCategory,
                                         memberName As String,
                                         sourceFile As String,
                                         sourceLine As Integer)
            MASVirtualizationConsumerFaultDiagnostics.RecordFailure(
                ex:=ex,
                diagnosticCode:=diagnosticCode,
                consumerName:=consumerName,
                boundaryContext:=context,
                reason:=reason,
                severity:=severity,
                category:=category,
                memberName:=memberName,
                sourceFile:=sourceFile,
                sourceLine:=sourceLine)
        End Sub
    End Class

End Namespace
