Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    Public Class RepairLogTable
        Enum ColNamesEnum
            ''' <summary>
            ''' 维修日志索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 维修产品索引
            ''' </summary>
            ProductID

            ''' <summary>
            ''' 维修产品条码
            ''' </summary>
            DUT_SN

            ''' <summary>
            ''' 产品错误代码
            ''' </summary>
            ErrCode

            ''' <summary>
            ''' 维修原因类型
            ''' </summary>
            RepairType

            ''' <summary>
            ''' 维修人工注释
            ''' </summary>
            RepairComment

            ''' <summary>
            ''' 维修产品日期
            ''' </summary>
            RepairDate

            ''' <summary>
            ''' 维修产品结果
            ''' </summary>
            RepairResult

            ''' <summary>
            ''' 产品图像文件名1
            ''' </summary>
            ProductImg1
            
            ''' <summary>
            ''' 产品图像文件名2
            ''' </summary>
            ProductImg2
            
            ''' <summary>
            ''' 产品图像文件名3
            ''' </summary>
            ProductImg3

            ''' <summary>
            ''' 产品图像文件名4
            ''' </summary>
            ProductImg4
        End Enum

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

        ''' <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($"`{ColNamesEnum.ID}` int(11) NOT NULL AUTO_INCREMENT COMMENT '维修日志索引',")
                builder.Append($"`{ColNamesEnum.ProductID}` int(11) Not NULL COMMENT '维修产品索引',")
                builder.Append($"`{ColNamesEnum.DUT_SN}` varchar(32) Not NULL COMMENT '维修产品条码',")
                builder.Append($"`{ColNamesEnum.ErrCode}` varchar(32) DEFAULT NULL COMMENT '产品错误代码',")
                builder.Append($"`{ColNamesEnum.RepairType}` int(11) DEFAULT NULL COMMENT '维修原因类型',")
                builder.Append($"`{ColNamesEnum.RepairComment}` varchar(254) DEFAULT NULL COMMENT '维修人工注释',")
                builder.Append($"`{ColNamesEnum.RepairDate}` datetime DEFAULT NULL COMMENT '维修产品日期',")
                builder.Append($"`{ColNamesEnum.RepairResult}` bit(1) Not NULL DEFAULT 0 COMMENT '维修产品结果',")
                builder.Append($"`{ColNamesEnum.ProductImg1}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名1',")
                builder.Append($"`{ColNamesEnum.ProductImg2}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名2',")
                builder.Append($"`{ColNamesEnum.ProductImg3}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名3',")
                builder.Append($"`{ColNamesEnum.ProductImg4}` varchar(64) DEFAULT NULL COMMENT '产品图像文件名4',")
                builder.Append($"PRIMARY KEY (`{ColNamesEnum.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