Option Strict On
Option Explicit On

Namespace Nexamas.UI.FloatRuntime

    ' ============================================================
    ' MASFloatRuntime Contract
    ' Class: MASFloatResolvedRequest
    '
    ' Purpose:
    '   Represents the internal resolved form of Descriptor defaults plus
    '   Request overrides.
    '
    ' Responsibility:
    '   Carries the effective slot, scope, layer, presentation, and Shield
    '   options that runtime internals will use for policy and lifecycle.
    '
    ' Owns:
    '   Resolved request data only.
    '
    ' Does Not Own:
    '   Lifecycle execution.
    '   Host state.
    '   Session state.
    '   Queue state.
    '   Result delivery.
    '
    ' Allowed Dependencies:
    '   MASFloatDescriptor.
    '   MASFloatRequest.
    '   MASFloatSlot.
    '   MASFloatScope.
    '   MASFloatLayerLevel.
    '   MASFloatPresentation.
    '   MASFloatShieldOptions.
    '
    ' Forbidden Dependencies:
    '   Legacy Overlay classes.
    '   MASFloatCoordinator.
    '   MASFloatHost.
    '   Feature-owned lifecycle services.
    '
    ' Lifecycle Role:
    '   Created before policy/lifecycle execution for one Show request.
    '
    ' Threading:
    '   Created and consumed on the runtime lifecycle path.
    '   Runtime must marshal lifecycle work to UI thread if needed.
    '
    ' Mutation Rules:
    '   Internal mutable properties are allowed during resolution.
    '   After policy accepts the resolved request, Coordinator should treat
    '   it as stable for that lifecycle.
    '
    ' Invariants:
    '   ResolvedRequest is internal runtime state.
    '   It must never become public API.
    '   Descriptor and Request remain separate concepts.
    '
    ' Failure Rules:
    '   Missing Descriptor or Request is invalid.
    '   Missing Presentation or Shield is normalized during creation.
    ' ============================================================
    Friend NotInheritable Class MASFloatResolvedRequest

        Friend Property Descriptor As MASFloatDescriptor

        Friend Property Request As MASFloatRequest

        Friend Property Slot As MASFloatSlot

        Friend Property Scope As MASFloatScope

        Friend Property Layer As MASFloatLayerLevel

        Friend Property Presentation As MASFloatPresentation

        Friend Property Shield As MASFloatShieldOptions

        Friend Shared Function Create(
            descriptor As MASFloatDescriptor,
            request As MASFloatRequest
        ) As MASFloatResolvedRequest
            If descriptor Is Nothing Then
                Throw New ArgumentNullException(NameOf(descriptor))
            End If

            If request Is Nothing Then
                Throw New ArgumentNullException(NameOf(request))
            End If

            Dim descriptorSnapshot As MASFloatDescriptor = descriptor.Clone()
            Dim requestSnapshot As MASFloatRequest = request.CloneShallow()

            Dim resolvedPresentation As MASFloatPresentation = Nothing

            If requestSnapshot.RequestedPresentation IsNot Nothing Then
                resolvedPresentation = requestSnapshot.RequestedPresentation.Clone()
            ElseIf descriptorSnapshot.DefaultPresentation IsNot Nothing Then
                resolvedPresentation = descriptorSnapshot.DefaultPresentation.Clone()
            Else
                resolvedPresentation = New MASFloatPresentation()
            End If

            Dim resolvedShield As MASFloatShieldOptions =
                If(requestSnapshot.Shield Is Nothing,
                   MASFloatShieldOptions.None.Clone(),
                   requestSnapshot.Shield.Clone())

            Return New MASFloatResolvedRequest() With {
                .Descriptor = descriptorSnapshot,
                .Request = requestSnapshot,
                .Slot = If(requestSnapshot.RequestedSlot.HasValue,
                           requestSnapshot.RequestedSlot.Value,
                           descriptorSnapshot.DefaultSlot),
                .Scope = If(requestSnapshot.RequestedScope.HasValue,
                            requestSnapshot.RequestedScope.Value,
                            descriptorSnapshot.DefaultScope),
                .Layer = If(requestSnapshot.RequestedLayer.HasValue,
                            requestSnapshot.RequestedLayer.Value,
                            descriptorSnapshot.DefaultLayer),
                .Presentation = resolvedPresentation,
                .Shield = resolvedShield
            }
        End Function

    End Class

End Namespace