"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.env = void 0;
exports.getEnv = getEnv;
var node_path_1 = require("node:path");
var dotenv_1 = require("dotenv");
var zod_1 = require("zod");
dotenv_1.default.config({ override: true, quiet: true });
var envSchema = zod_1.z.object({
    PORT: zod_1.z.coerce.number().default(3100),
    APP_TIME_ZONE: zod_1.z.string().default('Asia/Seoul'),
    DB_TIME_ZONE: zod_1.z.string().default('Asia/Seoul'),
    DB_CLIENT: zod_1.z.string().default('pg'),
    DB_HOST: zod_1.z.string().default('localhost'),
    DB_PORT: zod_1.z.coerce.number().default(5432),
    DB_NAME: zod_1.z.string().default('work_db'),
    DB_USER: zod_1.z.string().default('work_user'),
    DB_PASSWORD: zod_1.z.string().default('change-me'),
    DB_SSL: zod_1.z
        .string()
        .default('false')
        .transform(function (value) { return value === 'true'; }),
    PLAN_WORKER_ENABLED: zod_1.z
        .string()
        .default('true')
        .transform(function (value) { return value === 'true'; }),
    PLAN_WORKER_INTERVAL_MS: zod_1.z.coerce.number().default(10000),
    PLAN_WORKER_ID: zod_1.z.string().optional(),
    PLAN_GIT_REPO_PATH: zod_1.z.string().default('/workspace/repo'),
    PLAN_MAIN_PROJECT_REPO_PATH: zod_1.z.string().optional(),
    PLAN_RELEASE_BRANCH: zod_1.z.string().default('release'),
    PLAN_MAIN_BRANCH: zod_1.z.string().default('main'),
    PLAN_GIT_USER_NAME: zod_1.z.string().default('how2ice'),
    PLAN_GIT_USER_EMAIL: zod_1.z.string().default('how2ice@naver.com'),
    PLAN_CODEX_RUNNER_PATH: zod_1.z.string().default('/workspace/repo-scripts/run-plan-codex-once.mjs'),
    PLAN_CODEX_ENABLED: zod_1.z
        .string()
        .default('true')
        .transform(function (value) { return value === 'true'; }),
    PLAN_LOCAL_MAIN_MODE: zod_1.z
        .string()
        .default('true')
        .transform(function (value) { return value === 'true'; }),
    PLAN_CODEX_BIN: zod_1.z.string().default('codex'),
    PLAN_CODEX_TEMPLATE_HOME: zod_1.z.string().optional(),
    PLAN_PREVIEW_BASE_URL: zod_1.z.string().optional(),
    PLAN_PREVIEW_URL_TEMPLATE: zod_1.z.string().optional(),
    IOS_NOTIFICATION_ENABLED: zod_1.z
        .string()
        .default('false')
        .transform(function (value) { return value === 'true'; }),
    WEB_PUSH_ENABLED: zod_1.z
        .string()
        .default('false')
        .transform(function (value) { return value === 'true'; }),
    WEB_PUSH_VAPID_PUBLIC_KEY: zod_1.z.string().optional(),
    WEB_PUSH_VAPID_PRIVATE_KEY: zod_1.z.string().optional(),
    WEB_PUSH_SUBJECT: zod_1.z.string().default('mailto:how2ice@naver.com'),
    APNS_KEY_ID: zod_1.z.string().optional(),
    APNS_TEAM_ID: zod_1.z.string().optional(),
    APNS_BUNDLE_ID: zod_1.z.string().optional(),
    APNS_PRIVATE_KEY: zod_1.z.string().optional(),
    APNS_PRIVATE_KEY_PATH: zod_1.z.string().optional(),
    APNS_PRODUCTION: zod_1.z
        .string()
        .default('false')
        .transform(function (value) { return value === 'true'; }),
    SERVER_COMMAND_ACCESS_TOKEN: zod_1.z.string().default('usr_7f3a9c2d8e1b4a6f'),
    SERVER_COMMAND_API_BASE_URL: zod_1.z.string().optional(),
    SERVER_COMMAND_API_ACCESS_TOKEN: zod_1.z.string().optional(),
    SERVER_COMMAND_API_RESTART_PATH_TEMPLATE: zod_1.z.string().default('/api/server-commands/{key}/actions/restart'),
    SERVER_COMMAND_PROJECT_ROOT: zod_1.z.string().default(node_path_1.default.resolve(process.cwd(), '../../..')),
    SERVER_COMMAND_MAIN_PROJECT_ROOT: zod_1.z.string().default('/workspace/main-project'),
    SERVER_COMMAND_TEST_URL: zod_1.z.string().default('https://preview.sm-home.cloud/'),
    SERVER_COMMAND_REL_URL: zod_1.z.string().default('https://rel.sm-home.cloud/'),
    SERVER_COMMAND_PROD_URL: zod_1.z.string().default('https://sm-home.cloud/'),
    SERVER_COMMAND_WORK_SERVER_URL: zod_1.z.string().default('http://127.0.0.1:3100/health'),
    SERVER_COMMAND_RUNNER_URL: zod_1.z.string().default('http://host.docker.internal:3211/health'),
    SERVER_COMMAND_RUNNER_ACCESS_TOKEN: zod_1.z.string().default('local-server-command-runner'),
    SERVER_COMMAND_RUNNER_HEARTBEAT_FILE: zod_1.z.string().optional(),
    SERVER_COMMAND_TEST_SERVICE: zod_1.z.string().default('app'),
    SERVER_COMMAND_REL_SERVICE: zod_1.z.string().default('release-app'),
    SERVER_COMMAND_PROD_SERVICE: zod_1.z.string().default('prod-app'),
    SERVER_COMMAND_WORK_SERVER_SERVICE: zod_1.z.string().default('work-server'),
    WORK_SERVER_DIST_DIR: zod_1.z.string().default('dist'),
});
function parseEnv() {
    var _a;
    dotenv_1.default.config({ override: true, quiet: true });
    var parsedEnv = envSchema.parse(process.env);
    return __assign(__assign({}, parsedEnv), { PLAN_MAIN_PROJECT_REPO_PATH: (_a = parsedEnv.PLAN_MAIN_PROJECT_REPO_PATH) !== null && _a !== void 0 ? _a : parsedEnv.PLAN_GIT_REPO_PATH });
}
function getEnv() {
    var _a;
    var parsedEnv = parseEnv();
    if (!((_a = process.env.TZ) === null || _a === void 0 ? void 0 : _a.trim())) {
        process.env.TZ = parsedEnv.APP_TIME_ZONE;
    }
    return parsedEnv;
}
exports.env = getEnv();
