function obrigatoria(nome: string): string {
  const valor = process.env[nome];
  if (!valor) {
    throw new Error(`Variável de ambiente ausente: ${nome}`);
  }
  return valor;
}

export const env = {
  porta: Number(process.env.PORT ?? 3000),
  dbHost: process.env.DB_HOST ?? "localhost",
  dbPort: Number(process.env.DB_PORT ?? 3306),
  dbUser: process.env.DB_USER ?? "",
  dbPassword: process.env.DB_PASSWORD ?? "",
  dbName: process.env.DB_NAME ?? "",
  jwtSecret: process.env.JWT_SECRET ?? "dev-secret-trocar-em-producao",
  nodeEnv: process.env.NODE_ENV ?? "development",
  get obrigatorias() {
    return {
      dbUser: obrigatoria("DB_USER"),
      dbPassword: obrigatoria("DB_PASSWORD"),
      dbName: obrigatoria("DB_NAME"),
      jwtSecret: obrigatoria("JWT_SECRET"),
    };
  },
};
