import { readFileSync } from 'fs';
import { parse } from 'dotenv';

function applyEnv(env: Record<string, string>) {
  for (const key in env) {
    process.env[key] = env[key];
  }
}

const __dirname = import.meta.dirname;

const serverEnvVars = parse(readFileSync(__dirname + '/../packages/services/server/.env', 'utf-8'));

applyEnv({
  POSTGRES_USER: serverEnvVars.POSTGRES_USER,
  POSTGRES_PASSWORD: serverEnvVars.POSTGRES_PASSWORD,
  POSTGRES_DB: serverEnvVars.POSTGRES_DB,
  POSTGRES_PORT: serverEnvVars.POSTGRES_PORT,
  POSTGRES_HOST: serverEnvVars.POSTGRES_HOST,
  HIVE_APP_BASE_URL: serverEnvVars.WEB_APP_URL,
  EXTERNAL_COMPOSITION_SECRET: 'secretsecret',
  CLICKHOUSE_USER: serverEnvVars.CLICKHOUSE_USERNAME,
  CLICKHOUSE_PASSWORD: serverEnvVars.CLICKHOUSE_PASSWORD,
  HIVE_ENCRYPTION_SECRET: serverEnvVars.HIVE_ENCRYPTION_SECRET,
  SUPERTOKENS_REFRESH_TOKEN_KEY: serverEnvVars.SUPERTOKENS_REFRESH_TOKEN_KEY,
  SUPERTOKENS_ACCESS_TOKEN_KEY: serverEnvVars.SUPERTOKENS_ACCESS_TOKEN_KEY,
});
