import { defineCollection, z } from 'astro:content';

const cycles = defineCollection({
  type: 'data',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    duration: z.string(),
    hours: z.number(),
    level: z.enum(['grado-superior', 'grado-medio']),
    slug: z.string(),
    modules: z.array(z.string()),
    competences: z.array(z.string()),
    keywords: z.array(z.string()),
    icon: z.string().optional(),
  }),
});

const modules = defineCollection({
  type: 'data',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    cycle: z.string(),
    hours: z.number(),
    slug: z.string(),
    competences: z.array(z.string()),
    technologies: z.array(z.string()),
    keywords: z.array(z.string()),
  }),
});

const articles = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    description: z.string(),
    date: z.date(),
    updated: z.date().optional(),
    author: z.string().default('Ornitonautas'),
    keywords: z.array(z.string()),
    category: z.enum(['guia', 'tutorial', 'noticia', 'recurso']),
    readingTime: z.number(),
    relatedCycles: z.array(z.string()).optional(),
    relatedModules: z.array(z.string()).optional(),
  }),
});

const faqs = defineCollection({
  type: 'data',
  schema: z.object({
    question: z.string(),
    answer: z.string(),
    category: z.enum(['general', 'ciclos', 'admisión', 'empleo', 'metodología']),
    keywords: z.array(z.string()),
  }),
});

const glossary = defineCollection({
  type: 'data',
  schema: z.object({
    term: z.string(),
    definition: z.string(),
    category: z.enum(['programación', 'bases-datos', 'redes', 'desarrollo-web', 'general']),
    relatedTerms: z.array(z.string()).optional(),
    keywords: z.array(z.string()),
  }),
});

export const collections = {
  cycles,
  modules,
  articles,
  faqs,
  glossary,
};
