import winston from './winston'; //TODO这里日志记录使用了log4net.dll需要解决对应的方案 可以使用vuejs-logger来代替
import LoginUserInfo from '../RunningParameters/LoginUserInfo'; // 假设 LoginUserInfo 定义在该文件中TODO：缺用户模块

// 假设 LogWriter 类的实现
class LogWriter {
    private static instance: LogWriter;
    private logData: any[] = [];

    private constructor() { }

    public static get Instance() {
        return this.instance || (this.instance = new this());
    }

    public AddLogData(data: any) {
        this.logData.push(data);
    }

    public SaveLog() {
        // 实现保存日志的逻辑
    }
}

// 定义日志记录器
const lg1 = winston.createLogger("lg1");
const lg2 = winston.createLogger("lg2");
const lg3 = winston.createLogger("lg3");
const lg4 = winston.createLogger("lg4");
const lg5 = winston.createLogger("lg5");

// 日志文件开关状态
const dics: { [key: string]: string } = {
    'System.log': 'on',
    'Debug.log': 'on',
    'Message.log': 'on',
    'Error.log': 'on',
};

// 创建连接
function CreateConnection(tellerNo: string, tradeDate: string) {
    // 实现创建连接的逻辑
}

// 关闭连接
function CloseConnection() {
    // 实现关闭连接的逻辑
}

// 系统正常运行的输出日志
export function SystemInfo(logDetail: string) {
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    LogWriter.Instance.AddLogData({ logger: lg1, level: 'debug', message: logDetail });
    LogWriter.Instance.SaveLog();
    CloseConnection();
}

// 交易正常运行的输出日志
export function TradeInfo(logDetail: string, tradeNum = '****') {
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    LogWriter.Instance.AddLogData({ logger: lg2, level: 'debug', message: logDetail, tradeNum });
    LogWriter.Instance.SaveLog();
    CloseConnection();
}

// 交易异常的输出日志
export function TradeErrorInfo(errMsg: string, ex: Error, tradeNum = '****') {
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    LogWriter.Instance.AddLogData({ logger: lg3, level: 'error', message: errMsg, tradeNum, ex });
    LogWriter.Instance.SaveLog();
    CloseConnection();
}

// 普通异常(不属于交易异常)的输出日志
export function SystemErrorInfo(errMsg: string, ex: Error) {
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    LogWriter.Instance.AddLogData({ logger: lg5, level: 'error', message: errMsg, ex });
    LogWriter.Instance.SaveLog();
    CloseConnection();
}

// 通讯内容的输出日志
export function CommunicationInfo(msg: string, tradeNum = '****') {
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    LogWriter.Instance.AddLogData({ logger: lg4, level: 'debug', message: msg, tradeNum });
    LogWriter.Instance.SaveLog();
    CloseConnection();
}

// 获取待上传的目录路径
export function GetUploadDataPath(isChecked: boolean): string {
    CloseConnection();
    if (isChecked) {
        if (CanbeSent(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate)) {
            return GetBackUp();
        }
    } else {
        return GetBackUp();
    }
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
    return '';
}

// 更改输出配置
export function ChangeOutput() {
    CloseConnection();
    CreateConnection(LoginUserInfo.TellerNo, LoginUserInfo.TradeDate);
}

// 判断日志文件是否满足上传条件
function CanbeSent(path: string, tradeDate: string): boolean {
    // 实现判断逻辑
    return false;
}

// 检查日志文件是否能写入
function CheckSwitchOfFile(logger: "", dic: { [key: string]: string }) {//TODO(logger: winston.Logger, dic: { [key: string]: string })
    // 实现检查逻辑
}

// 获取日志文件的最近上传时间
function GetLastSentTime(fInfo: any): Date {
    // 实现获取时间逻辑
    return new Date();
}

// 获取日志文件的大小
function GetSizeOfFile(fInfo: any): number {
    // 实现获取大小逻辑
    return 0;
}
const enum Enum {
    A = 1,
    B = A * 2,
}
// 为指定的日志记录器添加输出文件
function SetAppender(logger: "", appender: any) {//TODO(logger: winston.Logger, appender: any)
    // 实现添加输出文件逻辑
}

// 创建输出文件
function CreateAppender(tellerNo: string, fileName: string): any {
    // 实现创建输出文件逻辑
    return {};
}

// 截屏函数
function CutScreen(): string {
    // 实现截屏逻辑
    return '';
}

// 对待上传的目录进行备份，并返回目录路径
function GetBackUp(): string {
    // 实现备份逻辑
    return '';
}
