Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class ProductTypesTable
        Enum ColNames
            ID
            ''' <summary>
            ''' 产品类型
            ''' </summary>
            ProductType

            ''' <summary>
            ''' 修改日期
            ''' </summary>
            UpdateTime

            ''' <summary>
            ''' 备注
            ''' </summary>
            Remark
        End Enum


        Public Shared Property TableName() As String = "TBL_ProductTypes"

        ''' <summary>
        ''' 建表语句
        ''' </summary>
        ''' <returns>建表语句</returns>
        Public Shared Function CreateTableString(dbName As String, Optional dbType As DbExecutor.DbTypeEnum = DbExecutor.DbTypeEnum.Mysql) As String
            Dim builder As New StringBuilder
            If dbType = DbExecutor.DbTypeEnum.Mysql Then
                builder.Append($"CREATE TABLE If Not Exists `{dbName}`.`{TableName}` ")

                builder.Append("(")
                builder.Append($"`{ColNames.ID}` int(11) Not NULL AUTO_INCREMENT,")
                builder.Append($"`{ColNames.ProductType}` varchar(255) Not NULL,")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.Remark}` varchar(255) DEFAULT NULL,")
                builder.Append($"PRIMARY KEY (`{ColNames.ID}`) ")
                builder.Append(")")
                builder.Append("ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;")
            Else
                Throw New Exception($"{TableName}-Invalid db type :{dbType}")
            End If

            Return builder.ToString()
        End Function
    End Class

End Namespace