Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Customer
    ''' <summary>
    ''' 项目总表
    ''' </summary>
    Public Class ProjectTable
        Enum ColNames
            ''' <summary>
            ''' 项目唯一标识
            ''' </summary>
            ID
            ''' <summary>
            ''' 项目类型索引
            ''' </summary>
            ProductTypeID
            ''' <summary>
            ''' 项目名称
            ''' </summary>
            ProjectName
            ''' <summary>
            ''' 项目描述
            ''' </summary>
            Description
            ''' <summary>
            ''' 创建人
            ''' </summary>
            UserID
            ''' <summary>
            ''' 创建时间
            ''' </summary>
            CreateTime

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

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

            ''' <summary>
            ''' 预览图
            ''' </summary>
            ImageName

            ''' <summary>
            ''' 预览图
            ''' </summary>
            PreviewImage

            ''' <summary>
            ''' 单价
            ''' </summary>
            Price

            ''' <summary>
            ''' 单价单位
            ''' </summary>
            Currency
            ''' <summary>
            ''' 当前项目是否有效
            ''' </summary>
            IsValid
            ''' <summary>
            ''' 最后有效日期
            ''' </summary>
            EolDate

            ''' <summary>
            ''' 录入条码总表类型，0无订单，1有订单
            ''' </summary>
            SnType
        End Enum


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

        ''' <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.ProductTypeID}` int(11) Not NULL,")
                builder.Append($"`{ColNames.ProjectName}` varchar(64) Not NULL,")
                builder.Append($"`{ColNames.Description}` varchar(64) DEFAULT NULL,")
                builder.Append($"`{ColNames.UserID}` int(11) Not NULL,")
                builder.Append($"`{ColNames.CreateTime}` datetime NOT NULL DEFAULT current_timestamp(),")
                builder.Append($"`{ColNames.UpdateTime}` datetime NOT NULL DEFAULT current_timestamp() COMMENT '更新时间',")
                builder.Append($"`{ColNames.EolDate}` datetime DEFAULT NULL,")
                builder.Append($"`{ColNames.Remark}` varchar(255) DEFAULT NULL,")
                builder.Append($"`{ColNames.ImageName}` varchar(255) DEFAULT NULL,")
                builder.Append($"`{ColNames.PreviewImage}` mediumblob DEFAULT NULL,")
                builder.Append($"`{ColNames.Price}` float(10,2) DEFAULT NULL,")
                builder.Append($"`{ColNames.Currency}` varchar(10) DEFAULT NULL,")
                builder.Append($"`{ColNames.IsValid}` tinyint(4) DEFAULT 1,")
                builder.Append($"`{ColNames.SnType}` int(11) NOT NULL DEFAULT 1,")
                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