Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' Sn关联信息表
    ''' </summary>
    Public Class ImportInfoTable

        Enum ColNames
            ''' <summary>
            ''' 索引
            ''' </summary>
            ID
            ''' <summary>
            ''' 项目唯一标识
            ''' </summary>
            ProjectID
            ''' <summary>
            ''' 产品序号唯一标识
            ''' </summary>
            Barcode
            ''' <summary>
            ''' 录入时间
            ''' </summary>
            ImportDateTime
            ''' <summary>
            ''' 更新时间,用于同步下载
            ''' </summary>
            UpdateTime
        End Enum

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

        ''' <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.ProjectID}` int(11) NOT NULL DEFAULT -1 COMMENT '项目唯一标识',")
                builder.Append($"`{ColNames.Barcode}` varchar(32) NOT NULL COMMENT '产品序号唯一标识',")
                builder.Append($"`{ColNames.ImportDateTime}` 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
