Option Strict On
Option Explicit On

Imports System
Imports SkiaSharp

Namespace Nexamas.UI.FloatRuntime

    ' ============================================================
    ' MASFloatRuntime Contract
    ' Class: MASFloatRequest
    '
    ' Purpose:
    '   Describes one concrete request to show a Float instance now.
    '
    ' Responsibility:
    '   Carries caller intent, content, ownership, optional overrides,
    '   Shield options, pixel-space geometry, and lifecycle callbacks.
    '
    ' Owns:
    '   Request data only.
    '
    ' Does Not Own:
    '   Descriptor defaults.
    '   Resolved runtime state.
    '   Lifecycle execution.
    '   Policy authorization.
    '   Host placement.
    '   Session lifetime.
    '   Result delivery timing.
    '
    ' Allowed Dependencies:
    '   IMASFloatContent.
    '   MASFloatHandle.
    '   MASFloatSlot.
    '   MASFloatScope.
    '   MASFloatLayerLevel.
    '   MASFloatPresentation.
    '   MASFloatShowPolicy.
    '   MASFloatShieldOptions.
    '   MASFloatClosedEventArgs.
    '   SkiaSharp.SKRect for pixel-space geometry.
    '
    ' Forbidden Dependencies:
    '   Legacy Overlay classes.
    '   MASFloatCoordinator.
    '   MASFloatPolicyEngine.
    '   MASFloatRuntimeState.
    '   MASFloatHost.
    '   Feature-owned lifecycle services.
    '
    ' Lifecycle Role:
    '   Submitted to MASFloatRuntime.Show.
    '   Resolved internally into MASFloatResolvedRequest before lifecycle
    '   execution begins.
    '
    ' Threading:
    '   Request should be built by the caller before Show.
    '   Runtime must marshal Show to the UI thread if needed.
    '
    ' Mutation Rules:
    '   Public mutable properties are allowed before Show.
    '   After Show is called, caller must not mutate the request.
    '   Runtime must snapshot or resolve values before internal use.
    '
    ' Invariants:
    '   Request describes one show intent.
    '   Descriptor describes registered Float type.
    '   Request must have FloatKey.
    '   Request must have OwnerKey when descriptor requires owner.
    '   All geometry in this contract is pixel-space and must use Px suffix.
    '
    ' Failure Rules:
    '   Missing FloatKey is invalid.
    '   Missing Content is invalid for visual/content Floats.
    '   ParentFloat scope without ParentHandle must be rejected by policy.
    ' ============================================================
    Friend NotInheritable Class MASFloatRequest

        Private _ownerKey As String = String.Empty

        Private _ownerToken As MASFloatOwnerToken = MASFloatOwnerToken.Empty

        Friend Property FloatKey As String = String.Empty

        Friend Property Content As IMASFloatContent

        Friend Property OwnerKey As String
            Get
                Return _ownerKey
            End Get
            Set(value As String)
                _ownerKey = MASFloatOwnerToken.NormalizeKey(value)
                _ownerToken = MASFloatOwnerToken.FromKey(_ownerKey)
            End Set
        End Property

        Friend Property OwnerToken As MASFloatOwnerToken
            Get
                Return If(_ownerToken, MASFloatOwnerToken.Empty)
            End Get
            Set(value As MASFloatOwnerToken)
                _ownerToken = If(value, MASFloatOwnerToken.Empty)
                _ownerKey = _ownerToken.Key
            End Set
        End Property

        Friend Property ParentHandle As MASFloatHandle

        Friend Property RequestedSlot As MASFloatSlot?

        Friend Property RequestedScope As MASFloatScope?

        Friend Property RequestedLayer As MASFloatLayerLevel?

        Friend Property RequestedPresentation As MASFloatPresentation

        Friend Property ShowPolicy As MASFloatShowPolicy = MASFloatShowPolicy.FailIfOccupied

        Friend Property Shield As MASFloatShieldOptions = MASFloatShieldOptions.None

        Friend Property AnchorRectPx As SKRect = SKRect.Empty

        Friend Property AvailableBoundsPx As SKRect = SKRect.Empty

        Friend Property InitialBoundsPx As SKRect = SKRect.Empty

        Friend Property OnOpened As Action(Of MASFloatHandle)

        Friend Property OnClosed As Action(Of MASFloatClosedEventArgs)

        Friend Function CloneShallow() As MASFloatRequest
            Return New MASFloatRequest() With {
                .FloatKey = Me.FloatKey,
                .Content = Me.Content,
                .OwnerToken = Me.OwnerToken,
                .ParentHandle = Me.ParentHandle,
                .RequestedSlot = Me.RequestedSlot,
                .RequestedScope = Me.RequestedScope,
                .RequestedLayer = Me.RequestedLayer,
                .RequestedPresentation = If(Me.RequestedPresentation Is Nothing, Nothing, Me.RequestedPresentation.Clone()),
                .ShowPolicy = Me.ShowPolicy,
                .Shield = If(Me.Shield Is Nothing, Nothing, Me.Shield.Clone()),
                .AnchorRectPx = Me.AnchorRectPx,
                .AvailableBoundsPx = Me.AvailableBoundsPx,
                .InitialBoundsPx = Me.InitialBoundsPx,
                .OnOpened = Me.OnOpened,
                .OnClosed = Me.OnClosed
            }
        End Function

    End Class

End Namespace