Option Strict On
Option Explicit On

Namespace Nexamas.UI.FloatRuntime

    ' ============================================================
    ' MASFloatRuntime Contract
    ' Class: MASFloatClosedEventArgs
    '
    ' Purpose:
    '   Provides the only official external result-delivery object for a
    '   closed Float.
    '
    ' Responsibility:
    '   Exposes Float identity, close reason, final result, and convenience
    '   status flags after the Float has actually closed.
    '
    ' Owns:
    '   Closed event data only.
    '
    ' Does Not Own:
    '   Lifecycle transition execution.
    '   Result production.
    '   Host removal.
    '   Policy authorization.
    '   Queue continuation.
    '
    ' Allowed Dependencies:
    '   MASFloatHandle.
    '   MASFloatResult.
    '   MASFloatCloseReason.
    '   MASFloatResultStatus.
    '
    ' Forbidden Dependencies:
    '   Legacy Overlay classes.
    '   MASFloatCoordinator.
    '   MASFloatRuntimeState.
    '   MASFloatHost.
    '   MASFloatPolicyEngine.
    '
    ' Lifecycle Role:
    '   Created only after the Float reaches Closed.
    '   Used for external OnClosed callbacks and closed events.
    '
    ' Threading:
    '   Immutable after construction.
    '   Must be delivered on the UI thread by runtime-owned lifecycle flow.
    '
    ' Mutation Rules:
    '   No public setters.
    '
    ' Invariants:
    '   ClosedEventArgs is the only external result delivery object.
    '   External Accepted, Cancelled, Dismissed, or Failed state must not be
    '   delivered before Closed.
    '
    ' Failure Rules:
    '   Missing Handle is invalid.
    '   Missing Result is normalized to MASFloatResult.None.
    ' ============================================================
    Friend NotInheritable Class MASFloatClosedEventArgs
        Inherits EventArgs

        Friend ReadOnly Property Handle As MASFloatHandle

        Friend ReadOnly Property FloatKey As String

        Friend ReadOnly Property OwnerKey As String

        Friend ReadOnly Property OwnerToken As MASFloatOwnerToken

        Friend ReadOnly Property Result As MASFloatResult

        Friend ReadOnly Property CloseReason As MASFloatCloseReason

        Friend ReadOnly Property WasAccepted As Boolean
            Get
                Return Me.Result.Status = MASFloatResultStatus.Accepted
            End Get
        End Property

        Friend ReadOnly Property WasCancelled As Boolean
            Get
                Return Me.Result.Status = MASFloatResultStatus.Cancelled
            End Get
        End Property

        Friend ReadOnly Property WasDismissed As Boolean
            Get
                Return Me.Result.Status = MASFloatResultStatus.Dismissed
            End Get
        End Property

        Friend ReadOnly Property Failed As Boolean
            Get
                Return Me.Result.Status = MASFloatResultStatus.Failed
            End Get
        End Property

        Friend Sub New(
            handle As MASFloatHandle,
            result As MASFloatResult,
            closeReason As MASFloatCloseReason
        )
            If handle Is Nothing Then
                Throw New ArgumentNullException(NameOf(handle))
            End If

            Me.Handle = handle
            Me.FloatKey = handle.FloatKey
            Me.OwnerKey = handle.OwnerKey
            Me.OwnerToken = handle.OwnerToken
            Me.Result = If(result, MASFloatResult.None)
            Me.CloseReason = closeReason
        End Sub

    End Class

End Namespace