import { z } from 'zod';

const CatalogueItemSchema = z.object({
  ref:    z.string().max(100),
  label:  z.string().max(500),
  price:  z.number().min(0),
  tva_tx: z.number().min(0).max(100),
});

const CorrectionSchema = z.object({
  designation_ai:   z.string().max(500).optional(),
  designation_user: z.string().max(500).optional(),
  detail_ai:        z.string().max(2000).optional(),
  detail_user:      z.string().max(2000).optional(),
});

export const GenerateSchema = z.object({
  licence_key: z.string().regex(/^LAU-[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/),
  notes:       z.string().min(10).max(5000),
  photos:      z.array(z.string().startsWith('data:image/')).max(10),
  catalogue:   z.array(CatalogueItemSchema).max(2000),
  contexte:    z.string().max(200).optional().default(''),
  verbosity:   z.enum(['concise', 'detailed']).default('concise'),
  corrections: z.array(CorrectionSchema).max(10).default([]),
});

export const CheckLicenceSchema = z.object({
  licence_key: z.string().min(1),
});

export type GenerateInput = z.infer<typeof GenerateSchema>;
