Option Strict On
Option Explicit On

Imports System

Namespace Nexamas.UI.Virtualization

    ''' <summary>
    ''' Records the commercial contract boundary between virtualization and source projection for one large-data surface.
    ''' A binding may admit that a surface-owned projection performs a full pass; that admission is intentional and prevents
    ''' the shared virtualization proof from being misread as a data/projection scale proof.
    ''' </summary>
    Friend NotInheritable Class MASVirtualizationProjectionScopeBinding
        Friend Sub New(id As String,
                       displayName As String,
                       surfaceType As Type,
                       scope As MASVirtualizationProjectionScope,
                       sourceProjectionOwnerName As String,
                       projectionOperationName As String,
                       renderWindowProofName As String,
                       projectionScaleContractName As String,
                       admitsFullProjectionPass As Boolean,
                       virtualizationCoreOwnsProjection As Boolean,
                       projectionScaleRequiresSeparateGate As Boolean)
            Me.Id = Normalize(id)
            Me.DisplayName = Normalize(displayName)
            Me.SurfaceType = surfaceType
            Me.Scope = scope
            Me.SourceProjectionOwnerName = Normalize(sourceProjectionOwnerName)
            Me.ProjectionOperationName = Normalize(projectionOperationName)
            Me.RenderWindowProofName = Normalize(renderWindowProofName)
            Me.ProjectionScaleContractName = Normalize(projectionScaleContractName)
            Me.AdmitsFullProjectionPass = admitsFullProjectionPass
            Me.VirtualizationCoreOwnsProjection = virtualizationCoreOwnsProjection
            Me.ProjectionScaleRequiresSeparateGate = projectionScaleRequiresSeparateGate
        End Sub

        Friend ReadOnly Property Id As String
        Friend ReadOnly Property DisplayName As String
        Friend ReadOnly Property SurfaceType As Type
        Friend ReadOnly Property Scope As MASVirtualizationProjectionScope
        Friend ReadOnly Property SourceProjectionOwnerName As String
        Friend ReadOnly Property ProjectionOperationName As String
        Friend ReadOnly Property RenderWindowProofName As String
        Friend ReadOnly Property ProjectionScaleContractName As String
        Friend ReadOnly Property AdmitsFullProjectionPass As Boolean
        Friend ReadOnly Property VirtualizationCoreOwnsProjection As Boolean
        Friend ReadOnly Property ProjectionScaleRequiresSeparateGate As Boolean

        Friend ReadOnly Property IsSurfaceOwnedProjection As Boolean
            Get
                Return Scope = MASVirtualizationProjectionScope.SurfaceOwnedFullProjection AndAlso
                       AdmitsFullProjectionPass AndAlso
                       Not VirtualizationCoreOwnsProjection AndAlso
                       ProjectionScaleRequiresSeparateGate
            End Get
        End Property

        Friend ReadOnly Property IsStructurallyValid As Boolean
            Get
                Return Id.Length > 0 AndAlso
                       DisplayName.Length > 0 AndAlso
                       SurfaceType IsNot Nothing AndAlso
                       SurfaceType.IsClass AndAlso
                       System.Enum.IsDefined(GetType(MASVirtualizationProjectionScope), Scope) AndAlso
                       SourceProjectionOwnerName.Length > 0 AndAlso
                       ProjectionOperationName.Length > 0 AndAlso
                       RenderWindowProofName.Length > 0 AndAlso
                       ProjectionScaleContractName.Length > 0 AndAlso
                       IsSurfaceOwnedProjection
            End Get
        End Property

        Private Shared Function Normalize(value As String) As String
            Return If(value, String.Empty).Trim()
        End Function

    End Class

End Namespace
