Imports System.Text
Imports UTS_Core.Database

Namespace UTSModule.DbTableModel.Manage
    Public Class ServiceLogTable
        ''' <summary>数据库操作记录表枚举值</summary>
        Enum ColNamesEnum

            ''' <summary>日志索引</summary>
            ID

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

            ''' <summary>应用名称</summary>
            AppName

            ''' <summary>应用版本</summary>
            AppVersion

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

            ''' <summary>设备公网IP</summary>
            DevPublicIP

            ''' <summary>设备内网IP地址</summary>
            DevPrivateIP

            ''' <summary>设备MAC</summary>
            DevMac

            ''' <summary>设备系统版本</summary>
            DevOS

            ''' <summary>设备名称</summary>
            DevName

            ''' <summary>设备用户名</summary>
            DevUserName

            ''' <summary>设备网络状态</summary>
            DevOnline

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

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

        End Enum

        Public Shared ReadOnly TableName As String = "TBL_UTS_Manage_ServiceLog"

        ''' <summary>
        ''' Sqlite数据库建表语句
        ''' </summary>
        ''' <returns>建表语句</returns>
        Public Shared Function CreateTableString(Optional dbType As DbExecutor.DbTypeEnum = DbExecutor.DbTypeEnum.Mysql) As String
            Dim createStr As New StringBuilder
            If dbType = DbExecutor.DbTypeEnum.Mysql Then

                createStr.Append($"Create Table If Not Exists `{TableName}`")
                createStr.Append(" (")
                createStr.Append($"`{ColNamesEnum.ID}` NOT NULL AUTO_INCREMENT ,")
                createStr.Append($"`{ColNamesEnum.CompanyName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.AppName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.AppVersion}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DateTime}` DateTime NOT NULL ,")
                createStr.Append($"`{ColNamesEnum.DevPublicIP}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevPrivateIP}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevMac}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevOS}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevUserName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevOnline}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.LogType}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.LogText}` text,")
                createStr.Append($"PRIMARY KEY (`ID`)")
                createStr.Append(" );")

            ElseIf 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.CompanyName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.AppName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.AppVersion}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DateTime}` DateTime NOT NULL ,")
                createStr.Append($"`{ColNamesEnum.DevPublicIP}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevPrivateIP}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevMac}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevOS}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevUserName}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.DevOnline}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.LogType}` varchar(254),")
                createStr.Append($"`{ColNamesEnum.LogText}` text")
                createStr.Append(" );")
            End If

            Return createStr.ToString()
        End Function

    End Class
End Namespace