Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Manage
    Public Class DataServiceLogTable
        Enum ColNames
            ''' <summary>
            ''' 索引
            ''' </summary>
            ID

            ''' <summary>
            ''' 数据服务索引
            ''' </summary>
            ServiceID

            ''' <summary>
            ''' 数据服务版本
            ''' </summary>
            ServiceVersion

            ''' <summary>
            ''' 更新服务版本
            ''' </summary>
            UpdateServiceVersion

            ''' <summary>
            ''' 厂商名称
            ''' </summary>
            VendorName

            ''' <summary>
            ''' 生成日期与时间
            ''' </summary>
            DateTime

            ''' <summary>
            ''' 公网IP
            ''' </summary>
            PublicIp

            ''' <summary>
            ''' 私网IP
            ''' </summary>
            PrivateIp

            ''' <summary>
            ''' Mac地址
            ''' </summary>
            Mac

            ''' <summary>
            ''' 日志类型
            ''' </summary>
            LogType

            ''' <summary>
            ''' 日志内容
            ''' </summary>
            LogText
        End Enum


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


        ''' <summary>
        ''' 建表语句
        ''' </summary>
        ''' <returns>建表语句</returns>
        Public Shared Function CreateTableString(dbName As String, Optional dbType As DbExecutor.DbTypeEnum = DbExecutor.DbTypeEnum.Mysql) As String
            Dim createStr As New StringBuilder
            If dbType = DbExecutor.DbTypeEnum.Sqlite Then
                createStr.Append($"Create Table If Not Exists `{TableName}`")
                createStr.Append(" (")
                createStr.Append($"`{ColNames.ID}` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,")
                createStr.Append($"`{ColNames.ServiceID}` int(11) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.ServiceVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.UpdateServiceVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.VendorName}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.PrivateIp}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.PublicIp}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.DateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNames.LogType}` varchar(32) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.LogText}` text DEFAULT NULL ")
                createStr.Append(" );")
            ElseIf dbType = DbExecutor.DbTypeEnum.Mysql Then
                createStr.Append($"Create Table If Not Exists `{dbName}`.`{TableName}`")
                createStr.Append(" (")
                createStr.Append($"`{ColNames.ID}` int(11) NOT NULL AUTO_INCREMENT ,")
                createStr.Append($"`{ColNames.ServiceID}` int(11) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.ServiceVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.UpdateServiceVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.VendorName}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.PrivateIp}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.PublicIp}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.DateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNames.LogType}` varchar(32) DEFAULT NULL ,")
                createStr.Append($"`{ColNames.LogText}` text DEFAULT NULL ,")
                createStr.Append($"`{ColNames.ID}` int(11) NOT NULL AUTO_INCREMENT ,")
                createStr.Append($"PRIMARY KEY (`{ColNames.ID}`)")
                createStr.Append(" );")
            Else
                Throw New Exception($"Unknown Type{dbType}!")
            End If

            Return createStr.ToString()
        End Function


    End Class
End Namespace