Imports System.Collections.Generic
Imports CharterDotCom.CommonEntities.Library.Enumerations
' 8/2007 jg added
Imports System.Reflection
Imports System.Text

''' <summary>
''' Bundle Class contains data specific to a Bundled-Offer, including
''' various Extensions (Data, Voice, Video)
''' </summary>
''' <remarks>This correlates to the Web Service G2B BundledOfferType and
''' is used to pass data from the App Server back to the Web Server
''' layer.<BR/>
''' As of version 4.1, all fields from the G2B Web Service call are made
''' available in this interface.  Previous versions of this object only
''' returned a subset of the fields - only the fields needed by the
''' current version of the Web Server front-end were returned.</remarks>
<Serializable()> _
<DebuggerDisplay("Bundle: ID={_id}, Name={_name}, Description={_description}, Price={_price.ToString()}, {_children.Count} Plans")> _
Public Class Bundle
    Private m_id As String
    Private m_name As String
    Private m_description As String
    Private m_listPrice As Decimal
    Private m_price As Decimal
    Private m_installPrice As Decimal
    Private m_installDescription As String
    Private m_category As GWYCategory
    Private m_serviceType As ServiceType
    Private m_selected As Boolean
    Private m_children As Dictionary(Of String, ServicePlan)
    Private m_effectiveDate As Date
    Private m_promoName As String
    Private m_promoDisclaimer As String
    Private m_marketinginfo As String
    Private m_marketingdetail As String

    ' 8/2007 jwg added for g2b v4.1
    Private m_contract As EntityG2BServices.ContractType

    Private m_billingCode As String
    Private m_priceFrequency As PriceFrequency
    Private m_childrenFeature As Dictionary(Of String, Feature)
    Private m_mediumname As String = String.Empty
    Private m_techSupport As String = String.Empty

    Private m_priceFrequencyG2B As PriceFrequency
    Private m_priceDescription As String = String.Empty
    Private m_installPriceFrequency As PriceFrequency
    Private m_HWPriceFrequency As PriceFrequency
    Private m_HWPrice As Decimal = 0

    Private m_HWpriceDescription As String = String.Empty
    Private m_DepositPriceFrequency As PriceFrequency
    Private m_DepositPrice As Decimal = 0
    Private m_DepositpriceDescription As String = String.Empty
    Private m_Version As Decimal = 0

    Private m_MovesOffer As Boolean
    Private m_HardwareType As Dictionary(Of String, EntityG2BServices.HardwareType)
    Private m_IncludedItems As Dictionary(Of String, EntityG2BServices.IncludedItemsType)
    Private m_MarketingInfoG2B As EntityG2BServices.MarketingInfoType
    Private m_CustomizationList As Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)

    Private m_DataExtension As EntityG2BServices.DataExtensionType = New EntityG2BServices.DataExtensionType()
    Private m_VoiceExtension As EntityG2BServices.VoiceExtensionType = New EntityG2BServices.VoiceExtensionType()
    Private m_VideoExtension As EntityG2BServices.VideoExtensionType = New EntityG2BServices.VideoExtensionType()

    Public Property DataExtension() As EntityG2BServices.DataExtensionType
        Get
            Return m_DataExtension
        End Get
        Set(ByVal value As EntityG2BServices.DataExtensionType)
            m_DataExtension = value
        End Set
    End Property


    Public Property VoiceExtension() As EntityG2BServices.VoiceExtensionType
        Get
            Return m_VoiceExtension
        End Get
        Set(ByVal value As EntityG2BServices.VoiceExtensionType)
            m_VoiceExtension = value
        End Set
    End Property


    Public Property VideoExtension() As EntityG2BServices.VideoExtensionType
        Get
            Return m_VideoExtension
        End Get
        Set(ByVal value As EntityG2BServices.VideoExtensionType)
            m_VideoExtension = value
        End Set
    End Property

    Public Property BillingCode() As String
        Get
            Return m_billingCode
        End Get
        Set(ByVal value As String)
            m_billingCode = value
        End Set
    End Property

    Public Property Features() As Dictionary(Of String, Feature)

        Get
            Return m_childrenFeature
        End Get
        Set(ByVal value As Dictionary(Of String, Feature))
            m_childrenFeature = value
        End Set
    End Property

    Public Property PriceFreq() As PriceFrequency
        Get
            Return m_priceFrequency
        End Get
        Set(ByVal value As PriceFrequency)
            m_priceFrequency = value
        End Set
    End Property

    Public Property Contract() As EntityG2BServices.ContractType
        Get
            Return m_contract
        End Get
        Set(ByVal value As EntityG2BServices.ContractType)
            m_contract = value
        End Set
    End Property

    ''' <summary>Service Plan Medium Name</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property MediumName() As String
        Get
            Return m_mediumname
        End Get
        Set(ByVal value As String)
            m_mediumname = value
        End Set
    End Property

    ''' <summary>Service Plan Tech Support</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property TechSupport() As String
        Get
            Return m_techSupport
        End Get
        Set(ByVal value As String)
            m_techSupport = value
        End Set
    End Property

    ''' <summary>Service Plan Price Frequency from G2B</summary>
    ''' <value></value>
    ''' <returns>PriceFrequency from G2B (other PriceFrequency
    ''' property is fixed at Monthly)</returns>
    ''' <remarks>Weekly, Monthly, One Time, etc/</remarks>
    Public Property PriceFrequencyG2B() As PriceFrequency
        Get
            Return m_priceFrequencyG2B
        End Get
        Set(ByVal value As PriceFrequency)
            m_priceFrequencyG2B = value
        End Set
    End Property

    ''' <summary>Service Plan Price Description</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property PriceDescription() As String
        Get
            Return m_priceDescription
        End Get
        Set(ByVal value As String)
            m_priceDescription = value
        End Set
    End Property

    ''' <summary>Service Plan Install Price Frequency</summary>
    ''' <value></value>
    ''' <returns>InstallPrice Frequency from G2B</returns>
    ''' <remarks>Weekly, Monthly, One Time, etc/</remarks>
    Public Property InstallPriceFrequency() As PriceFrequency
        Get
            Return m_installPriceFrequency
        End Get
        Set(ByVal value As PriceFrequency)
            m_installPriceFrequency = value
        End Set
    End Property

    ''' <summary>Service Plan HW Price</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    Public Property HWPrice() As Decimal
        Get
            Return m_HWPrice
        End Get
        Set(ByVal value As Decimal)
            m_HWPrice = value
        End Set
    End Property

    ''' <summary>Service Plan Hardware Price Frequency</summary>
    ''' <value></value>
    ''' <returns>HardwarePriceFrequency from G2B</returns>
    ''' <remarks>Weekly, Monthly, One Time, etc/</remarks>
    Public Property HWPriceFrequency() As PriceFrequency
        Get
            Return m_HWPriceFrequency
        End Get
        Set(ByVal value As PriceFrequency)
            m_HWPriceFrequency = value
        End Set
    End Property
    ''' <summary>Service Plan HardWare price Description</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property HWPriceDescription() As String
        Get
            Return m_HWpriceDescription
        End Get
        Set(ByVal value As String)
            m_HWpriceDescription = value
        End Set
    End Property

    ''' <summary>Service Plan Deposit Price</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks></remarks>
    Public Property DepositPrice() As Decimal
        Get
            Return m_DepositPrice
        End Get
        Set(ByVal value As Decimal)
            m_DepositPrice = value
        End Set
    End Property

    ''' <summary>Service Plan Deposit Price Frequency</summary>
    ''' <value></value>
    ''' <returns>DepositPriceFrequency from G2B</returns>
    ''' <remarks>Weekly, Monthly, One Time, etc/</remarks>
    Public Property DepositPriceFrequency() As PriceFrequency
        Get
            Return m_DepositPriceFrequency
        End Get
        Set(ByVal value As PriceFrequency)
            m_DepositPriceFrequency = value
        End Set
    End Property

    ''' <summary>Service Plan Deposit price Description</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property DepositPriceDescription() As String
        Get
            If m_DepositpriceDescription Is Nothing Then
                Return String.Empty
            Else
                Return m_DepositpriceDescription
            End If
        End Get
        Set(ByVal value As String)
            m_DepositpriceDescription = value
        End Set
    End Property

    ''' <summary>Service Plan Version</summary>
    ''' <value></value>
    ''' <returns>String</returns>
    ''' <remarks>new field for v4.1.  not used in front end</remarks>
    Public Property Version() As Decimal
        Get
            Return m_Version
        End Get
        Set(ByVal value As Decimal)
            m_Version = value
        End Set
    End Property

    ''' <summary>Service Plan Hardware Types</summary>
    ''' <value></value>
    ''' <returns>Dictionary of Hardware Types</returns>
    ''' <remarks></remarks>
    Public Property HardwareTypes() As Dictionary(Of String, EntityG2BServices.HardwareType)
        Get
            Return m_HardwareType
        End Get
        Set(ByVal value As Dictionary(Of String, EntityG2BServices.HardwareType))
            m_HardwareType = value
        End Set
    End Property

    ''' <summary>Service Plan Included Item Types</summary>
    ''' <value></value>
    ''' <returns>Dictionary of Included Item Types</returns>
    ''' <remarks></remarks>
    Public Property IncludedItems() As Dictionary(Of String, EntityG2BServices.IncludedItemsType)
        Get
            Return m_IncludedItems
        End Get
        Set(ByVal value As Dictionary(Of String, EntityG2BServices.IncludedItemsType))
            m_IncludedItems = value
        End Set
    End Property

    ''' <summary>Service Plan Marketing Info</summary>
    ''' <value></value>
    ''' <returns>Dictionary of Marketing Info</returns>
    ''' <remarks></remarks>
    Public Property MarketingInfoG2B() As EntityG2BServices.MarketingInfoType
        Get
            Return m_MarketingInfoG2B
        End Get
        Set(ByVal value As EntityG2BServices.MarketingInfoType)
            m_MarketingInfoG2B = value
        End Set
    End Property

    ''' <summary>Service Plan Customizations</summary>
    ''' <value></value>
    ''' <returns>Dictionary of Customizations</returns>
    ''' <remarks></remarks>
    Public Property Customizations() As Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers)
        Get
            Return m_CustomizationList
        End Get
        Set(ByVal value As Dictionary(Of String, EntityG2BServices.CustomizationTypeQueryOffers))
            m_CustomizationList = value
        End Set
    End Property

    Public Property MovesOffer() As Boolean
        Get
            Return m_MovesOffer
        End Get
        Set(ByVal value As Boolean)
            m_MovesOffer = value
        End Set
    End Property

    ''' <summary>
    ''' Default no-arg constructor
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub

    ''' <summary>
    ''' Constructor to populate majority of fields
    ''' </summary>
    ''' <param name="id"></param>
    ''' <param name="name"></param>
    ''' <param name="description"></param>
    ''' <param name="price"></param>
    ''' <param name="listPrice"></param>
    ''' <param name="installPrice"></param>
    ''' <param name="installDescription"></param>
    ''' <param name="promoName"></param>
    ''' <param name="promoDisclaimer"></param>
    ''' <param name="marketinginfo"></param>
    ''' <param name="children"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal id As String, _
        ByVal name As String, _
        ByVal description As String, _
        ByVal price As Decimal, _
        ByVal listPrice As Decimal, _
        ByVal installPrice As Decimal, _
        ByVal installDescription As String, _
        ByVal promoName As String, _
        ByVal promoDisclaimer As String, _
        ByVal marketinginfo As String, _
        ByVal children As Dictionary(Of String, ServicePlan))

        m_id = id
        m_name = name
        m_description = description
        m_price = price
        m_listPrice = listPrice
        m_installPrice = installPrice
        m_installDescription = installDescription
        m_category = GWYCategory.UnSpecified
        m_serviceType = ServiceType.NotSpecified
        m_priceFrequency = PriceFrequency.Monthly
        m_children = children
        m_promoName = promoName
        m_promoDisclaimer = promoDisclaimer
        m_marketinginfo = marketinginfo

    End Sub

    ''' <summary>
    ''' Constructor to populate all fields defined in G2B 4.1 spec
    ''' </summary>
    ''' <param name="id"></param>
    ''' <param name="name"></param>
    ''' <param name="description"></param>
    ''' <param name="price"></param>
    ''' <param name="listPrice"></param>
    ''' <param name="installPrice"></param>
    ''' <param name="installDescription"></param>
    ''' <param name="promoName"></param>
    ''' <param name="promoDisclaimer"></param>
    ''' <param name="marketinginfo"></param>
    ''' <param name="children"></param>
    ''' <param name="pContract"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal id As String, _
        ByVal name As String, _
        ByVal description As String, _
        ByVal price As Decimal, _
        ByVal listPrice As Decimal, _
        ByVal installPrice As Decimal, _
        ByVal installDescription As String, _
        ByVal promoName As String, _
        ByVal promoDisclaimer As String, _
        ByVal marketinginfo As String, _
        ByVal children As Dictionary(Of String, ServicePlan), _
        ByVal pContract As EntityG2BServices.ContractType)

        Me.New(id, name, description, _
            price, listPrice, installPrice, _
            installDescription, promoName, promoDisclaimer, _
            marketinginfo, children)

        Me.Contract = pContract

    End Sub

    Public ReadOnly Property ID() As String
        Get
            Return m_id
        End Get
    End Property

    Public ReadOnly Property Name() As String
        Get
            Return m_name
        End Get
    End Property

    Public ReadOnly Property Description() As String
        Get
            Return m_description
        End Get
    End Property

    Public Property ListPrice() As Decimal
        Get
            Return m_listPrice
        End Get
        Set(ByVal value As Decimal)
            m_listPrice = value
        End Set
    End Property

    Public Property Price() As Decimal
        Get
            Return m_price
        End Get
        Set(ByVal value As Decimal)
            m_price = value
        End Set
    End Property

    Public Property InstallPrice() As Decimal
        Get
            Return m_installPrice
        End Get
        Set(ByVal value As Decimal)
            m_installPrice = value
        End Set
    End Property

    Public Property InstallDescription() As String
        Get
            Return m_installDescription
        End Get
        Set(ByVal value As String)
            m_installDescription = value
        End Set
    End Property

    Public ReadOnly Property Category() As GWYCategory
        Get
            Return m_category
        End Get
    End Property

    Public ReadOnly Property ServiceType() As ServiceType
        Get
            Return m_serviceType
        End Get
    End Property

    'Public ReadOnly Property IsSelected() As Boolean
    '  Get
    '    Return m_selected
    '  End Get
    'End Property

    Public ReadOnly Property ServicePlans() As Dictionary(Of String, ServicePlan)
        Get
            Return m_children
        End Get
    End Property

    Public ReadOnly Property PromoName() As String
        Get
            Return m_promoName
        End Get
    End Property

    Public ReadOnly Property PromoDisclaimer() As String
        Get
            Return m_promoDisclaimer
        End Get
    End Property

    Public ReadOnly Property MarketingInfo() As String
        Get
            Return m_marketinginfo
        End Get
    End Property

    Public Property MarketingDetail() As String
        Get
            Return m_marketingdetail
        End Get
        Set(ByVal value As String)
            m_marketingdetail = value
        End Set
    End Property

    ' 8/2007 jg added:
    Public Overrides Function ToString() As String
        Dim sb As New StringBuilder(1000)
        Dim t As Type
        Dim pi As PropertyInfo

        sb.Append("<BR/><H3>Bundle " & _
                    Me.ID & " " & _
                    Me.Name & "</H3>")
        ' use Reflection to get all properties of each Bundle
        t = Me.GetType()
        For Each mi As System.Reflection.PropertyInfo In t.GetProperties()
            ' see if we have a plain property or if the property is 
            ' a dictionary.  can't do "toString()" on a dictionary
            ' object
            pi = Me.GetType().GetProperty(mi.Name)
            If ((pi.PropertyType.IsPrimitive OrElse pi.PropertyType.Name = "String") _
              AndAlso _
                 pi.PropertyType.ToString().IndexOf("Dictionary") = -1) Then
                sb.Append("<BR/>&nbsp;&nbsp;&nbsp;" & _
                        mi.Name & " (<i>" & pi.PropertyType.Name & "</i>) : " & _
                        pi.GetValue(Me, Nothing))
            Else
                If (Me.GetType().GetProperty(mi.Name).PropertyType.AssemblyQualifiedName.ToUpper().IndexOf( _
                        "CharterDotCom.CommonEntities.Library.ServicePlan".ToUpper()) > -1) Then

                    sb.Append("<h4>Service Plans</h4>")
                    For Each kvp2 As KeyValuePair(Of String, ServicePlan) _
                        In pi.GetValue(Me, Nothing)
                        sb.Append("<BR/>" & _
                                    kvp2.ToString())
                    Next kvp2

                End If
            End If
        Next mi

        If (Me.Contract IsNot Nothing) Then
            sb.Append("<BR/>Contract : " & Me.Contract.ToString())
        End If

        Return sb.ToString()

    End Function
End Class