Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 维修原因类型表
    ''' </summary>
    Public Class RepairRequestTable

        Enum ColNames
            ''' <summary>
            ''' 索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 报修人员
            ''' </summary>
            UserID

            ''' <summary>
            ''' 报修单号
            ''' </summary>
            RepairRequestNum

            ''' <summary>
            ''' 产品类型
            ''' </summary>
            ProductID

            ''' <summary>
            ''' 产品条码
            ''' </summary>
            Barcode

            ''' <summary>
            ''' 产品图像
            ''' </summary>
            ProductImage

            ''' <summary>
            ''' 不良品来源
            ''' </summary>
            RejectSource

            ''' <summary>
            ''' 不良代码
            ''' </summary>
            RejectCode

            ''' <summary>
            ''' 不良说明
            ''' </summary>
            RejectDesc

            ''' <summary>
            ''' 创建日期
            ''' </summary>
            CreateTime

            ''' <summary>
            ''' 更新时间
            ''' </summary>
            UpdateTime

            ''' <summary>
            ''' 维修进度
            ''' </summary>
            RepairProgress

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

            ''' <summary>
            ''' 维修记录索引
            ''' </summary>
            RepairLogID

            ''' <summary>
            ''' 维修人员
            ''' </summary>
            Repairier

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

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


        ''' <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 '维修类型索引',")
                builder.Append($"`{ColNames.UserID}` int(11) NOT NULL COMMENT '报修人员',")
                builder.Append($"`{ColNames.RepairRequestNum}` varchar(254) NOT NULL COMMENT '报修单号',")
                builder.Append($"`{ColNames.ProductID}` int(11) NOT NULL COMMENT '产品类型',")
                builder.Append($"`{ColNames.Barcode}` varchar(64) NOT NULL COMMENT '产品条码',")
                builder.Append($"`{ColNames.ProductImage}` varchar(254) DEFAULT NULL COMMENT '产品图像',")
                builder.Append($"`{ColNames.RejectSource}` varchar(254) DEFAULT NULL COMMENT '不良品来源',")
                builder.Append($"`{ColNames.RejectCode}` varchar(254) DEFAULT NULL COMMENT '不良代码',")
                builder.Append($"`{ColNames.RejectDesc}` varchar(254) DEFAULT NULL 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($"`{ColNames.RepairProgress}` varchar(64) DEFAULT NULL COMMENT '维修进度',")
                builder.Append($"`{ColNames.RepairResult}` int(11) DEFAULT NULL COMMENT '维修结果',")
                builder.Append($"`{ColNames.RepairLogID}` int(11) DEFAULT NULL COMMENT '维修记录索引',")
                builder.Append($"`{ColNames.Repairier}` int(11) DEFAULT NULL COMMENT '维修人员',")
                builder.Append($"`{ColNames.Remark}` varchar(254) DEFAULT NULL 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
