"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clickhouseService = exports.redisClient = void 0;
exports.initializeClients = initializeClients;
const redis_1 = require("redis");
const clickhouseService_1 = require("./clickhouseService");
const database_1 = require("../database");
// ClickHouse settings
const clickhouseHost = process.env.CLICKHOUSE_HOST || "http://localhost:8123";
const clickhouseDatabase = process.env.CLICKHOUSE_DATABASE || "omsdb";
const clickhouseUser = process.env.CLICKHOUSE_USER || "ckuser";
const clickhousePassword = process.env.CLICKHOUSE_PASSWORD || "ckpassword";
// MongoDB connection
(0, database_1.connectToDatabase)();
// Redis client
const redisUri = process.env.REDIS_URI || "redis://localhost:6379";
const redisClient = (0, redis_1.createClient)({ url: redisUri });
exports.redisClient = redisClient;
redisClient.on("connect", () => console.log("Connected to Redis"));
redisClient.on("error", (err) => console.error("Redis connection error:", err));
// Clickhouse client
const clickhouseService = new clickhouseService_1.ClickhouseService(clickhouseHost, clickhouseDatabase, clickhouseUser, clickhousePassword);
exports.clickhouseService = clickhouseService;
const clickhouseTableName = "events";
// Initialize essential services
async function initializeClients() {
    try {
        await redisClient.connect();
        await clickhouseService.ensureTable(clickhouseTableName);
        console.log("[Clients] All essential services connected successfully.");
    }
    catch (err) {
        console.error("[Clients] Failed to connect to essential services:", err);
        process.exit(1);
    }
}
