import { registerAs } from '@nestjs/config';

export default registerAs('app', () => {
  const isProd = process.env.NODE_ENV === 'production';

  if (isProd && !process.env.JWT_SECRET) {
    throw new Error('JWT_SECRET environment variable is required in production');
  }
  if (isProd && !process.env.JWT_ACCESS_TOKEN_SECRET) {
    throw new Error('JWT_ACCESS_TOKEN_SECRET environment variable is required in production');
  }
  if (isProd && !process.env.JWT_REFRESH_TOKEN_SECRET) {
    throw new Error('JWT_REFRESH_TOKEN_SECRET environment variable is required in production');
  }

  return {
    port: parseInt(process.env.PORT ?? '4000', 10),
    jwtSecret: process.env.JWT_SECRET ?? 'dev-secret',
    jwtExpiresIn: process.env.JWT_EXPIRES_IN ?? '7d',
    frontendUrl: process.env.PORTAL_URL ?? 'http://localhost:3000',
    portalUrl: process.env.BACK_OFFICE_URL ?? 'http://localhost:3001',
  };
});
