Imports System.Text

Namespace Database.Base
    Public Class SearchCondition
        Enum ConditionType
            LessThan
            GreaterThen
            EqualTo
            LessThanOrEqualTo
            GreaterThenOrEqualTo
        End Enum

        Enum LogicType
            [And]
            [Or]
            [Not]
        End Enum


        ''' <summary>
        ''' 判断列名
        ''' </summary>
        ''' <returns></returns>
        Public Property ColName() As String

        ''' <summary>
        ''' 判断条件
        ''' </summary>
        ''' <returns></returns>
        Public Property Condition() As ConditionType = ConditionType.EqualTo

        ''' <summary>
        ''' 判断值
        ''' </summary>
        ''' <returns></returns>
        Public Property ColValue() As String

        ''' <summary>
        ''' 当前条件与上一个条件的逻辑关系
        ''' </summary>
        ''' <returns></returns>
        Public Property LogicPrevious() As LogicType = LogicType.And

        ''' <summary>
        ''' 将当前条件转换为字符串,不支持将条件逻辑关系同时转换
        ''' </summary>
        ''' <returns></returns>
        Public Overrides Function ToString() As String
            Dim stringBuilder As New StringBuilder
            stringBuilder.Append(" ")
            stringBuilder.Append(ColName)

            Select Case Condition
                Case ConditionType.EqualTo
                    stringBuilder.Append("=")
                Case ConditionType.LessThan
                    stringBuilder.Append("<")
                Case ConditionType.LessThanOrEqualTo
                    stringBuilder.Append("<=")
                Case ConditionType.GreaterThen
                    stringBuilder.Append(">")
                Case ConditionType.GreaterThenOrEqualTo
                    stringBuilder.Append(">=")
            End Select

            stringBuilder.Append($"'{ColValue}'")

            Return stringBuilder.ToString()
        End Function
    End Class
End Namespace