import { z } from 'zod';

export const catalogProjectSchema = z.object({
  id: z.string(),
  slug: z.string(),
  name: z.string(),
  description: z.string(),
  projectType: z.enum(['mod', 'plugin', 'modpack', 'resourcepack', 'shader']),
  downloads: z.number().int(),
  iconUrl: z.string().url().nullable(),
});

export const catalogSearchQuerySchema = z.object({
  q: z.string().min(1).max(128),
  gameVersion: z.string().min(1).max(32),
  softwareFamily: z.enum([
    'PAPER',
    'PURPUR',
    'FABRIC',
    'FORGE',
    'NEOFORGE',
    'QUILT',
  ]),
  limit: z.coerce.number().int().min(1).max(50).optional(),
});

export const catalogSearchResponseSchema = z.object({
  projects: z.array(catalogProjectSchema),
});

export const catalogVersionSchema = z.object({
  id: z.string(),
  projectId: z.string(),
  name: z.string(),
  versionNumber: z.string(),
  gameVersions: z.array(z.string()),
  loaders: z.array(z.string()),
  compatible: z.boolean(),
  publishedAt: z.string().datetime(),
});

export const catalogVersionsResponseSchema = z.object({
  versions: z.array(catalogVersionSchema),
});

export type CatalogProject = z.infer<typeof catalogProjectSchema>;
export type CatalogSearchQuery = z.infer<typeof catalogSearchQuerySchema>;
export type CatalogSearchResponse = z.infer<typeof catalogSearchResponseSchema>;
export type CatalogVersion = z.infer<typeof catalogVersionSchema>;
export type CatalogVersionsResponse = z.infer<typeof catalogVersionsResponseSchema>;
