Imports System.Text
Imports UTS_Core.Database

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

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

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

            ''' <summary>
            ''' 软件版本
            ''' </summary>
            AppVersion

            ''' <summary>
            ''' 注册日期与时间
            ''' </summary>
            RegisterDateTime

            ''' <summary>
            ''' 最后活动日期与时间
            ''' </summary>
            LastActiveDateTime

            ''' <summary>
            ''' 最后活动信息
            ''' </summary>
            LastInfomation

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

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


        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.LastInfomation}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.RegisterDateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.LastActiveDateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.Remark}` 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}` 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.LastInfomation}` varchar(254) DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.RegisterDateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.LastActiveDateTime}` DateTime DEFAULT NULL ,")
                createStr.Append($"`{ColNamesEnum.Remark}` text DEFAULT NULL ,")
                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