import { z } from 'zod';

const envSchema = z.object({
  NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
  PORT: z.string().default('3000'),
  DATABASE_URL: z.string().default('postgresql://postgres:A7fK9qR2@localhost:5435/qrmaster?schema=public'),
  NEXTAUTH_URL: z.string().default('http://localhost:3050'),
  NEXTAUTH_SECRET: z.string().default('development-secret-change-in-production'),
  GOOGLE_CLIENT_ID: z.string().optional(),
  GOOGLE_CLIENT_SECRET: z.string().optional(),
  REDIS_URL: z.string().optional(),
  IP_SALT: z.string().default('development-salt-change-in-production'),
  ENABLE_DEMO: z.string().default('false'),

  // Cloudflare R2 (S3 Compatible)
  R2_ACCOUNT_ID: z.string().optional(),
  R2_ACCESS_KEY_ID: z.string().optional(),
  R2_SECRET_ACCESS_KEY: z.string().optional(),
  R2_BUCKET_NAME: z.string().default('qrmaster-menus'),
  R2_PUBLIC_URL: z.string().optional(),
  MAX_UPLOAD_SIZE: z.string().default('10485760'), // 10MB default
});

// During build, we might not have all env vars, so we'll use defaults
const isBuildTime = process.env.NEXT_PHASE === 'phase-production-build' || !process.env.DATABASE_URL;

export const env = envSchema.parse(process.env);
