Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 产商的客户总表
    ''' </summary>
    Public Class VendorCustomerTable
        Enum ColNames
            ID

            CustomerAbbr

            CustomerName

            CreateTime

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

        End Enum

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

        ''' <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 COMMENT 'ID',")
                builder.Append($"`{ColNames.CustomerAbbr}` varchar(64) NOT NULL COMMENT '客户缩写',")
                builder.Append($"`{ColNames.CustomerName}` varchar(64) NOT NULL DEFAULT '' COMMENT '客户名称',")
                builder.Append($"`{ColNames.CreateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '创建时间',")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                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