import { MediaType } from '@components/MediaGallery/types';
import { z, defineCollection } from 'astro:content';

// AstroJS collection configuration

const games = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    has_content: z.boolean().optional(),
    date_added: z.coerce.date(),
    release: z.coerce.date(),
    developers: z.array(z.string()),
    genres: z.array(z.string()),
    status: z.enum([
      'Backlog',
      'On Line',
      'Playing',
      'Played',
      'Wishlist',
      'Want to Replay',
      'Always Playable',
      'Tried',
    ]),
    times_played: z.number(),
  }),
});

const blog = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    draft: z.boolean().optional(),
    tags: z.array(z.string()).optional(),
    published_at: z.coerce.date().optional(),
    updated_at: z.coerce.date().optional(),
  }),
});

const portafolio = defineCollection({
  type: 'content',
  schema: z.object({
    title: z.string(),
    draft: z.boolean().optional(),
    status: z.enum(['Backlog', 'Activo', 'Fixes', 'Finalizado']),
    tags: z.array(z.string()).optional(),
    technologies: z.array(z.string()),
    published_at: z.coerce.date().optional(),
    updated_at: z.coerce.date().optional(),
    media: z
      .array(
        z.object({
          type: z.nativeEnum(MediaType),
          url: z.string(),
          alt: z.string(),
          mime: z.string().optional(),
          thumbnail: z.string().optional(),
        }),
      )
      .catch([]),
  }),
});

export const collections = {
  games,
  blog,
  portafolio,
};
