Option Strict On
Option Explicit On

Namespace Nexamas.UI.Virtualization

    ''' <summary>
    ''' Realization request for one visible or overscanned item. It binds an item index to logical offset/extent and to the
    ''' stable container lease that a future UI consumer can map to a visual container.
    ''' </summary>
    Friend NotInheritable Class MASVirtualizationItemRequest

        Friend Sub New(index As Integer,
                       offsetPx As Single,
                       extentPx As Single,
                       containerLeaseId As Integer,
                       retainedFromPreviousPlan As Boolean,
                       acquiredFromRecyclePool As Boolean)
            Me.New(index, CDbl(offsetPx), CDbl(extentPx), containerLeaseId, retainedFromPreviousPlan, acquiredFromRecyclePool)
        End Sub

        Friend Sub New(index As Integer,
                       offsetPx As Double,
                       extentPx As Double,
                       containerLeaseId As Integer,
                       retainedFromPreviousPlan As Boolean,
                       acquiredFromRecyclePool As Boolean)
            Me.Index = Math.Max(0, index)
            Me.OffsetPxDouble = MASVirtualizationNumericGuard.NormalizeNonNegative(offsetPx)
            Me.ExtentPxDouble = MASVirtualizationNumericGuard.NormalizeNonNegative(extentPx)
            Me.OffsetPx = MASVirtualizationNumericGuard.ToSingleSaturated(Me.OffsetPxDouble)
            Me.ExtentPx = MASVirtualizationNumericGuard.ToSingleSaturated(Me.ExtentPxDouble)
            Me.ContainerLeaseId = Math.Max(0, containerLeaseId)
            Me.RetainedFromPreviousPlan = retainedFromPreviousPlan
            Me.AcquiredFromRecyclePool = acquiredFromRecyclePool
        End Sub

        Friend ReadOnly Property Index As Integer
        Friend ReadOnly Property OffsetPx As Single
        Friend ReadOnly Property ExtentPx As Single
        Friend ReadOnly Property OffsetPxDouble As Double
        Friend ReadOnly Property ExtentPxDouble As Double
        Friend ReadOnly Property ContainerLeaseId As Integer
        Friend ReadOnly Property RetainedFromPreviousPlan As Boolean
        Friend ReadOnly Property AcquiredFromRecyclePool As Boolean

        Friend ReadOnly Property EndPx As Single
            Get
                Return MASVirtualizationNumericGuard.ToSingleSaturated(EndPxDouble)
            End Get
        End Property

        Friend ReadOnly Property EndPxDouble As Double
            Get
                Return OffsetPxDouble + ExtentPxDouble
            End Get
        End Property

    End Class

End Namespace
