import { z } from 'zod';

export const CreateProjectSchema = z.object({
  name: z.string().min(1).max(100).regex(/^[a-z0-9-]+$/, 'Name must be lowercase alphanumeric with hyphens'),
  description: z.string().max(1000).default(''),
  prompt: z.string().max(10000).default(''),
  proxyModel: z.string().max(100).default(''),
  gated: z.boolean().default(true),
  llmProvider: z.string().max(100).optional(),
  llmModel: z.string().max(100).optional(),
  servers: z.array(z.string().min(1)).default([]),
  serverOverrides: z.record(z.string(), z.object({
    proxyModel: z.string().optional(),
  })).optional(),
  // Backward compat: accept but ignore proxyMode from old configs
  proxyMode: z.string().optional(),
}).transform(({ proxyMode: _ignored, ...rest }) => rest);

export const UpdateProjectSchema = z.object({
  description: z.string().max(1000).optional(),
  prompt: z.string().max(10000).optional(),
  proxyModel: z.string().max(100).optional(),
  gated: z.boolean().optional(),
  llmProvider: z.string().max(100).nullable().optional(),
  llmModel: z.string().max(100).nullable().optional(),
  servers: z.array(z.string().min(1)).optional(),
  serverOverrides: z.record(z.string(), z.object({
    proxyModel: z.string().optional(),
  })).optional(),
  // Backward compat: accept but ignore proxyMode from old configs
  proxyMode: z.string().optional(),
}).transform(({ proxyMode: _ignored, ...rest }) => rest);

export type CreateProjectInput = z.infer<typeof CreateProjectSchema>;
export type UpdateProjectInput = z.infer<typeof UpdateProjectSchema>;
