import { z } from 'zod';

const envSchema = z.object({
  NODE_ENV: z.string().default('development'),
  PORT: z.coerce.number().int().positive().default(3001),
  DATABASE_URL: z.string().url(),
  AUTH_SECRET: z.string().min(16, 'AUTH_SECRET must be at least 16 characters'),
  WK_BASE_URL: z.string().url().default('https://biedawo.org/api.php'),
  WK_APP_UID: z.string().optional(),
  WK_APP_KEY: z.string().optional(),
  WK_DEBUG_LOG: z.string().optional(),
  CATALOG_SYNC_CRON_ENABLED: z.string().optional(),
  CATALOG_SYNC_CRON: z.string().default('0 */2 * * *'),
  THIRD_PARTY_ORDER_SYNC_CRON_ENABLED: z.string().optional(),
  THIRD_PARTY_ORDER_SYNC_CRON: z.string().default('*/30 * * * *'),
});

export type AppEnv = z.infer<typeof envSchema>;

export function validateEnv(config: Record<string, unknown>): AppEnv {
  return envSchema.parse(config);
}
