Imports System.Text
Imports UTS_Core.Database

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

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

            ''' <summary>
            ''' 软件名称
            ''' </summary>
            AppName

            ''' <summary>
            ''' App版本
            ''' </summary>
            AppVersion

            ''' <summary>
            ''' 测试项目名
            ''' </summary>
            ProjectName

            ''' <summary>
            ''' 测试站名
            ''' </summary>
            StationName
            
            ''' <summary>
            ''' 测试流程名
            ''' </summary>
            TestPlan

            ''' <summary>
            ''' 生成日期
            ''' </summary>
            DateTime

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

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

        End Enum

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


        ''' <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($"`{ColNamesEnum.ID}` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ,")
                createStr.Append($"`{ColNamesEnum.ServiceID}` int(11) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.AppName}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.AppVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.ProjectName}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.StationName}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.TestPlan}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.DateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.LogType}` varchar(32) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.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($"`{ColNamesEnum.ID}` int(11) NOT NULL AUTO_INCREMENT ,")
                createStr.Append($"`{ColNamesEnum.ServiceID}` int(11) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.AppName}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.AppVersion}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.ProjectName}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.StationName}` varchar(64) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.TestPlan}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.DateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.LogType}` varchar(32) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.LogText}` text DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.ID}` int(11) NOT NULL AUTO_INCREMENT ,")
                createStr.Append($"PRIMARY KEY (`{ColNamesEnum.ID}`)")
                createStr.Append(" );")
            Else
                Throw New Exception($"Unknown Type{dbType}!")
            End If

            Return createStr.ToString()
        End Function
    End Class

End Namespace