// 环境变量验证
const validateEnv = () => {
  const requiredEnvVars = ["DATABASE_URL", "NEXTAUTH_SECRET", "NEXTAUTH_URL"];

  const missingVars = requiredEnvVars.filter(
    (varName) => !process.env[varName]
  );

  if (missingVars.length > 0) {
    throw new Error(`缺少必需的环境变量: ${missingVars.join(", ")}`);
  }
};

// 在开发环境中验证环境变量
if (process.env.NODE_ENV === "development") {
  validateEnv();
}

export const config = {
  app: {
    name: "录音应用",
    version: "1.0.0",
    environment: process.env.NODE_ENV || "development",
  },

  database: {
    url: process.env.DATABASE_URL!,
  },

  auth: {
    secret: process.env.NEXTAUTH_SECRET!,
    url: process.env.NEXTAUTH_URL!,
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    },
  },

  upload: {
    maxFileSize: 50 * 1024 * 1024, // 50MB
    allowedTypes: ["audio/webm", "audio/mp3", "audio/ogg", "audio/aac"],
    uploadDir: "public/recordings",
  },

  api: {
    rateLimit: {
      windowMs: 15 * 60 * 1000, // 15 minutes
      max: 100, // limit each IP to 100 requests per windowMs
    },
  },

  features: {
    audioVisualization: true,
    recordingPause: true,
    fileDownload: true,
    userSettings: true,
  },
} as const;

export type Config = typeof config;
