"use strict";
// SPDX-License-Identifier: Apache-2.0
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const LogService_1 = __importStar(require("./LogService"));
const BaseError_1 = __importStar(require("../../../core/error/BaseError"));
const winston = __importStar(require("winston"));
jest.mock("winston", () => {
    const originalWinston = jest.requireActual("winston");
    return {
        ...originalWinston,
        createLogger: jest.fn(() => ({
            log: jest.fn(),
        })),
    };
});
describe("LogService", () => {
    const mockLogger = {
        log: jest.fn(),
    };
    beforeEach(() => {
        winston.createLogger.mockReturnValue(mockLogger);
        // Re-initialize LogService singleton to inject the mock logger
        new LogService_1.default();
        jest.clearAllMocks();
    });
    it("should log TRACE level messages", () => {
        LogService_1.default.logTrace("Trace message", { key: "value" });
        expect(mockLogger.log).toHaveBeenCalledWith(LogService_1.LogLevel.TRACE, "Trace message", {
            timestamp: expect.any(String),
            other: [{ key: "value" }],
        });
    });
    it("should log INFO level messages", () => {
        LogService_1.default.logInfo("Info message", 123);
        expect(mockLogger.log).toHaveBeenCalledWith(LogService_1.LogLevel.INFO, "Info message", {
            timestamp: expect.any(String),
            other: [123],
        });
    });
    it("should log ERROR level messages", () => {
        LogService_1.default.logError("Some error message");
        expect(mockLogger.log).toHaveBeenCalledWith(LogService_1.LogLevel.ERROR, "Some error message", {
            timestamp: expect.any(String),
            other: [],
        });
    });
    it("should log BaseError properly", () => {
        class TestBaseError extends BaseError_1.default {
            constructor(code, message) {
                super(code, message);
            }
            toString() {
                return `BaseError: ${this.message}`;
            }
        }
        const error = new TestBaseError(BaseError_1.ErrorCode.Unexpected, "Something went wrong");
        LogService_1.default.logError(error, "context");
        expect(mockLogger.log).toHaveBeenCalledWith(LogService_1.LogLevel.ERROR, "BaseError: Something went wrong", {
            timestamp: expect.any(String),
            other: ["context"],
        });
    });
    it("should fallback to default log when non-BaseError thrown", () => {
        LogService_1.default.logError(new Error("Generic error"), "extra");
        expect(mockLogger.log).toHaveBeenCalledWith(LogService_1.LogLevel.ERROR, new Error("Generic error"), {
            timestamp: expect.any(String),
            other: ["extra"],
        });
    });
});
