Imports System.Text

Namespace Database.Mysql
    Public Class DataParam
        Enum DataTypeEnum
            '###############################数值类型#############################
            ''' <summary>
            ''' 1 byte,小整数值
            ''' </summary>
            Tinyint

            ''' <summary>
            ''' 2 bytes,大整数值
            ''' </summary>
            Smallint

            ''' <summary>
            ''' 3 bytes,大整数值
            ''' </summary>
            Mediumint
            
            ''' <summary>
            ''' 4 bytes,大整数值
            ''' </summary>
            Int

            ''' <summary>
            ''' 4 bytes,大整数值
            ''' </summary>
            [Integer]

            ''' <summary>
            ''' 8 bytes,极大整数值
            ''' </summary>
            Bigint

            ''' <summary>
            ''' 4 bytes,单精度浮点数值
            ''' </summary>
            Float


            ''' <summary>
            ''' 8 bytes,双精度浮点数值
            ''' </summary>
            [Double]



            '####################日期类型###############################

            ''' <summary>
            ''' 对DECIMAL(M,D) ，如果M>D，为M+2否则为D+2.小数值
            ''' </summary>
            [Decimal]
        
            ''' <summary>
            ''' 3 bytes,日期值,YYYY-MM-DD
            ''' </summary>
            [Date]


            ''' <summary>
            ''' 3 bytes,时间值或持续时间,HH:MM:SS
            ''' </summary>
            Time


            ''' <summary>
            ''' 1 bytes,年份值,YYYY
            ''' </summary>
            Year


            ''' <summary>
            ''' 8 bytes,混合日期和时间值,YYYY-MM-DD HH:MM:SS
            ''' </summary>
            Datetime

            ''' <summary>
            ''' 4 bytes,混合日期和时间值，时间戳,YYYYMMDD HHMMSS
            ''' </summary>
            Timestamp


            '####################字符类型###############################

            ''' <summary>
            ''' 0-255 bytes,定长字符串
            ''' </summary>
            [Char]

            ''' <summary>
            ''' 0-65535 bytes,变长字符串
            ''' </summary>
            Varchar

            ''' <summary>
            ''' 0-255 bytes,不超过 255 个字符的二进制字符串
            ''' </summary>
            Tinyblob

            
            ''' <summary>
            ''' 0-255 bytes,短文本字符串
            ''' </summary>
            Tinytext

            ''' <summary>
            ''' 0-65 535 bytes,二进制形式的长文本数据
            ''' </summary>
            Blob

            ''' <summary>
            ''' 0-65 535 bytes,长文本数据
            ''' </summary>
            Text


            ''' <summary>
            ''' 0-16 777 215 bytes,二进制形式的中等长度文本数据
            ''' </summary>
            Mediumblob

            ''' <summary>
            ''' 	0-16 777 215 bytes,中等长度文本数据
            ''' </summary>
            Mediumtext

            ''' <summary>
            ''' 0-4 294 967 295 bytes,二进制形式的极大文本数据
            ''' </summary>
            Longblob

            ''' <summary>
            ''' 0-4 294 967 295 bytes,极大文本数据
            ''' </summary>
            Longtext
        End Enum

        ''' <summary>
        ''' 列名
        ''' </summary>
        ''' <returns></returns>
        Public Property ColumnName() As String

        ''' <summary>
        ''' 当前值
        ''' </summary>
        ''' <returns></returns>
        Public Property Value() As String


        ''' <summary>
        ''' 默认值
        ''' </summary>
        ''' <returns></returns>
        Public Property DefaultValue() As String

        ''' <summary>
        ''' 数据类型
        ''' </summary>
        ''' <returns></returns>
        Public Property DataType() As DataTypeEnum

        ''' <summary>
        ''' 数据类型长度
        ''' </summary>
        ''' <returns></returns>
        Public Property DataTypeLength() As Integer

        ''' <summary>
        ''' 数据类型是否带符号
        ''' </summary>
        ''' <returns></returns>
        Public Property IsUnsigned() As Boolean



        ''' <summary>
        ''' 是否允许为空
        ''' </summary>
        ''' <returns></returns>
        Public Property IsNull() As Boolean = True

        ''' <summary>
        ''' 是否自动增长
        ''' </summary>
        ''' <returns></returns>
        Public Property IsAutoIncrement() As Boolean

        ''' <summary>
        ''' 是否为主键
        ''' </summary>
        ''' <returns></returns>
        Public Property IsPrimaryKey() As Boolean

        Public Function ToAddColString() As String
            Dim sb As New StringBuilder
            sb.Append($"`{ColumnName}`")

            Select Case DataType
                Case DataTypeEnum.Varchar,DataTypeEnum.[Char]
                    sb.Append($" {DataType}({DataTypeLength}) ")
                Case DataTypeEnum.Int
                    sb.Append($" {DataType}")
                    if IsUnsigned Then sb.Append($" Unsigned")
                    If IsAutoIncrement Then sb.Append($" AUTO_INCREMENT")
                Case Else
                    sb.Append($" {DataType}")
            End Select

            sb.Append(IIf(IsNull, " Default Null", " Not Null"))

            If IsPrimaryKey Then
                sb.Append($" PRIMARY KEY")
            End If

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