Imports System.Net
Imports System.Text.RegularExpressions

Public Class Mark
    ' Aus Search
    Private _RegistrationOfficeCode As String 'Datenbestand
    Private _RegistrationDate As String 'Tag der Eintragung im Register
    Private _RegistrationNumber As String 'Registernummer
    Private _MarkCurrentStatusCode As String 'Aktenzustand
    Private _MarkVerbalElementText As String 'Wiedergabe der Marke
    Private _MarkFeature As String 'Markenform
    Private _ApplicationDate As String 'Anmeldetag
    Private _ApplicationNumber As String 'Aktenzeichen
    Private _Applicant As String 'Inhaber
    Private _Representative As String 'Vertreter

    'Aus GetRegisterInfo
    Private _PublicationDate As Date ' Tag der Veröffentlichung
    Private _ExpiryDate As Date 'Schutzendedatum 
    Private _TerminationDate As Date 'Wirkungsdatum Löschung
    Private _OppositionPeriodStartDate As Date 'Beginn Widerspruchsfrist
    Private _OppositionPeriodEndDate As Date 'Ablauf Widerspruchsfrist
    Private _Image As ImageDetail

    Private Function ReplaceSingleQuote(value As String)
        Return value.Replace("'", "''")
    End Function

    Private Function ReplaceUmlauts(value As String)
        Dim result = value.Replace("ae", "ä")
        result = result.Replace("oe", "ö")
        result = result.Replace("ue", "ü")
        Return result
    End Function

    Private Function DecodeHTML(value As String)
        Return WebUtility.HtmlDecode(value)
    End Function

#Region "SearchProperties"
    Public Property RegistrationOfficeCode As String
        Get
            Return _RegistrationOfficeCode
        End Get
        Set(value As String)
            _RegistrationOfficeCode = value
        End Set
    End Property

    Public Property RegistrationDate As String
        Get
            Return _RegistrationDate
        End Get
        Set(value As String)
            _RegistrationDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property RegistrationNumber As String
        Get
            Return _RegistrationNumber
        End Get
        Set(value As String)
            _RegistrationNumber = value
        End Set
    End Property

    Public Property MarkCurrentStatusCode As String
        Get
            Return _MarkCurrentStatusCode
        End Get
        Set(value As String)
            value = ReplaceUmlauts(value)

            _MarkCurrentStatusCode = value
        End Set
    End Property

    Public Property MarkVerbalElementText As String
        Get
            Return _MarkVerbalElementText
        End Get
        Set(value As String)
            value = DecodeHTML(value)
            value = ReplaceSingleQuote(value)

            _MarkVerbalElementText = value
        End Set
    End Property

    Public Property MarkFeature As String
        Get
            Return _MarkFeature
        End Get
        Set(value As String)
            _MarkFeature = value
        End Set
    End Property

    Public Property ApplicationDate As String
        Get
            Return _ApplicationDate
        End Get
        Set(value As String)
            _ApplicationDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property ApplicationNumber As String
        Get
            Return _ApplicationNumber
        End Get
        Set(value As String)
            _ApplicationNumber = value
        End Set
    End Property

    Public Property Applicant As String
        Get
            Return _Applicant
        End Get
        Set(value As String)
            value = DecodeHTML(value)
            value = ReplaceSingleQuote(value)

            _Applicant = value
        End Set
    End Property

    Public Property Representative As String
        Get
            Return _Representative
        End Get
        Set(value As String)
            value = DecodeHTML(value)
            value = ReplaceSingleQuote(value)

            _Representative = value
        End Set
    End Property
#End Region

    Public Property PublicationDate As String
        Get
            Return _PublicationDate
        End Get
        Set(value As String)
            _PublicationDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property ExpiryDate As String
        Get
            Return _ExpiryDate
        End Get
        Set(value As String)
            _ExpiryDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property TerminationDate As String
        Get
            Return _TerminationDate
        End Get
        Set(value As String)
            _TerminationDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property OppositionPeriodStartDate As String
        Get
            Return _OppositionPeriodStartDate
        End Get
        Set(value As String)
            _OppositionPeriodStartDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property OppositionPeriodEndDate As String
        Get
            Return _OppositionPeriodEndDate
        End Get
        Set(value As String)
            _OppositionPeriodEndDate = Utils.ParseShortDate(value)
        End Set
    End Property

    Public Property Image As ImageDetail
        Get
            Return _Image
        End Get
        Set(value As ImageDetail)
            _Image = value
        End Set
    End Property

    Public Property MarkRecordDetails As New List(Of MarkRecordDetail)
    Public Property ClassificationKindCode As String
    Public Property ClassificationVersion As String
    Public Property GoodsServicesNotClassified As String
    Public Property ProposedLeadingClassNumber As String
    Public Property ClassificationDetail As New List(Of ClassificationDetail)
    Public Property Classification As String 'Klasse(n) Nizza

    Public ReadOnly Property ClassificationLong As String
        Get
            Dim result As String = ""

            If Not Me.GoodsServicesNotClassified Is Nothing Then
                Return Me.GoodsServicesNotClassified
            Else
                For Each c In Me.ClassificationDetail
                    result += String.Format("Klasse {0}: {1}{2}{1}", c.ClassNumber, vbNewLine, c.GoodsServicesDescription)
                Next
            End If

            If (result.EndsWith(";")) Then
                result = result.Substring(0, result.Length - 1)
            End If

            Return result
        End Get
    End Property

    Public Sub New()
    End Sub
End Class

Public Class ImageDetail
    Public BinaryImage As String
    Public Height As Integer
    Public Width As Integer
    Public Format As String

    Public Sub New()
    End Sub
End Class

Public Class ClassificationDetail
    Public ClassNumber As String
    Public GoodsServicesDescription As String

    Public Sub New()
    End Sub
End Class

Public Class MarkRecordDetail
    Public RecordIdentifier As String
    Public BasicRecordKind As String
    Public RecordCurrentStatusCode As String
    Public RecordCurrentStatusDate As Date
    Public RecordProcedureIncomplete As Boolean = False

    Public Sub New()
    End Sub
End Class
