// 模拟 CommonParames.TradeLog
const TradeLog = 'TradeLogger';

class Log {
    private name: string;

    constructor(name: string) {
        this.name = name;
    }

    debug(message: any, exception?: Error) {
        if (exception) {
            console.debug(`[${this.name}] ${message}`, exception);
        } else {
            console.debug(`[${this.name}] ${message}`);
        }
    }

    debugFormat(format: string, ...args: any[]) {
        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
            return typeof args[index] !== 'undefined' ? args[index] : match;
        });
        console.debug(`[${this.name}] ${formattedMessage}`);
    }

    error(message: any, exception?: Error) {
        if (exception) {
            console.error(`[${this.name}] ${message}`, exception);
        } else {
            console.error(`[${this.name}] ${message}`);
        }
    }

    errorFormat(format: string, ...args: any[]) {
        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
            return typeof args[index] !== 'undefined' ? args[index] : match;
        });
        console.error(`[${this.name}] ${formattedMessage}`);
    }

    fatal(message: any, exception?: Error) {
        if (exception) {
            console.error(`[${this.name}] FATAL: ${message}`, exception);
        } else {
            console.error(`[${this.name}] FATAL: ${message}`);
        }
    }

    fatalFormat(format: string, ...args: any[]) {
        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
            return typeof args[index] !== 'undefined' ? args[index] : match;
        });
        console.error(`[${this.name}] FATAL: ${formattedMessage}`);
    }

    info(message: any, exception?: Error) {
        if (exception) {
            console.info(`[${this.name}] ${message}`, exception);
        } else {
            console.info(`[${this.name}] ${message}`);
        }
    }

    infoFormat(format: string, ...args: any[]) {
        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
            return typeof args[index] !== 'undefined' ? args[index] : match;
        });
        console.info(`[${this.name}] ${formattedMessage}`);
    }

    warn(message: any, exception?: Error) {
        if (exception) {
            console.warn(`[${this.name}] ${message}`, exception);
        } else {
            console.warn(`[${this.name}] ${message}`);
        }
    }

    warnFormat(format: string, ...args: any[]) {
        const formattedMessage = format.replace(/{(\d+)}/g, (match, index) => {
            return typeof args[index] !== 'undefined' ? args[index] : match;
        });
        console.warn(`[${this.name}] ${formattedMessage}`);
    }

    get isDebugEnabled() {
        return true; // 简单模拟，实际可根据配置调整
    }

    get isErrorEnabled() {
        return true; // 简单模拟，实际可根据配置调整
    }

    get isFatalEnabled() {
        return true; // 简单模拟，实际可根据配置调整
    }

    get isInfoEnabled() {
        return true; // 简单模拟，实际可根据配置调整
    }

    get isWarnEnabled() {
        return true; // 简单模拟，实际可根据配置调整
    }

    get logger() {
        return this;
    }
}

const LogInstance = new Log(TradeLog);

export class TradeLogger {
    static debug(message: any, exception?: Error) {
        LogInstance.debug(message, exception);
    }

    static debugFormat(format: string, ...args: any[]) {
        LogInstance.debugFormat(format, ...args);
    }

    static error(message: any, exception?: Error) {
        LogInstance.error(message, exception);
    }

    static errorFormat(format: string, ...args: any[]) {
        LogInstance.errorFormat(format, ...args);
    }

    static fatal(message: any, exception?: Error) {
        LogInstance.fatal(message, exception);
    }

    static fatalFormat(format: string, ...args: any[]) {
        LogInstance.fatalFormat(format, ...args);
    }

    static info(message: any, exception?: Error) {
        LogInstance.info(message, exception);
    }

    static infoFormat(format: string, ...args: any[]) {
        LogInstance.infoFormat(format, ...args);
    }

    static warn(message: any, exception?: Error) {
        LogInstance.warn(message, exception);
    }

    static warnFormat(format: string, ...args: any[]) {
        LogInstance.warnFormat(format, ...args);
    }

    static get isDebugEnabled() {
        return LogInstance.isDebugEnabled;
    }

    static get isErrorEnabled() {
        return LogInstance.isErrorEnabled;
    }

    static get isFatalEnabled() {
        return LogInstance.isFatalEnabled;
    }

    static get isInfoEnabled() {
        return LogInstance.isInfoEnabled;
    }

    static get isWarnEnabled() {
        return LogInstance.isWarnEnabled;
    }

    static get Logger() {
        return LogInstance.logger;
    }
}