/**
 * Palace configuration schema — Zod-based env var validation.
 *
 * Products extend their backend config with these palace-specific vars.
 */

import { z } from 'zod';

export const palaceConfigSchema = z.object({
  PALACE_ENABLED: z
    .enum(['true', 'false'])
    .default('true')
    .transform(v => v === 'true'),

  PALACE_WAKE_UP_BUDGET: z.coerce.number().default(800),

  PALACE_DEDUP_THRESHOLD: z.coerce.number().min(0).max(1).default(0.9),

  PALACE_RELEVANCE_HALF_LIFE_DAYS: z.coerce.number().min(1).default(30),

  PALACE_MAX_MEMORIES_PER_SEARCH: z.coerce.number().min(1).default(20),

  PALACE_EXTRACTION_MAX_CHARS: z.coerce.number().min(100).default(6000),
});

export type PalaceConfig = z.infer<typeof palaceConfigSchema>;

/**
 * Parse palace config from environment.
 * Products typically merge this with their own config schema.
 */
export function parsePalaceConfig(
  env: Record<string, string | undefined> = process.env as Record<string, string | undefined>
): PalaceConfig {
  return palaceConfigSchema.parse(env);
}
