import { z } from 'zod';

export const addonTypeSchema = z.enum(['PLUGIN', 'MOD', 'MODPACK', 'DATAPACK']);

export const addonStatusSchema = z.enum([
  'PENDING',
  'INSTALLING',
  'INSTALLED',
  'FAILED',
  'REMOVING',
  'REMOVED',
]);

export const installedAddonSchema = z.object({
  id: z.string().uuid(),
  serverId: z.string().uuid(),
  provider: z.string(),
  projectId: z.string(),
  projectSlug: z.string(),
  projectName: z.string(),
  versionId: z.string(),
  versionNumber: z.string(),
  addonType: addonTypeSchema,
  fileName: z.string(),
  filePath: z.string(),
  status: addonStatusSchema,
  failureReason: z.string().nullable(),
  installedAt: z.string().datetime().nullable(),
  createdAt: z.string().datetime(),
});

export const addonListResponseSchema = z.object({
  addons: z.array(installedAddonSchema),
});

export const installAddonRequestSchema = z.object({
  projectId: z.string().min(1),
  versionId: z.string().min(1),
});

export const installAddonResponseSchema = z.object({
  addon: installedAddonSchema,
  jobId: z.string().optional(),
});

export type InstalledAddon = z.infer<typeof installedAddonSchema>;
export type AddonListResponse = z.infer<typeof addonListResponseSchema>;
export type InstallAddonRequest = z.infer<typeof installAddonRequestSchema>;
export type InstallAddonResponse = z.infer<typeof installAddonResponseSchema>;
