import { registerAs } from "@nestjs/config";
import { TypeOrmModuleOptions } from "@nestjs/typeorm";

export default registerAs(
  "database",
  (): TypeOrmModuleOptions => ({
    type: "postgres",
    host: process.env.DB_HOST ?? "localhost",
    port: parseInt(process.env.DB_PORT ?? "5433", 10),
    username: process.env.DB_USER ?? "postgres",
    password: process.env.DB_PASSWORD ?? "",
    database: process.env.DB_NAME ?? "edr_freight",
    entities: [__dirname + "/../**/*.entity.{ts,js}"],
    migrations: [__dirname + "/../../migrations/*.{ts,js}"],
    // Never enable synchronize in production. Use migrations.
    synchronize: process.env.NODE_ENV === "development",
    logging: process.env.NODE_ENV === "development",
  }),
);
