import { z } from "zod";

const softwareFamilyValues = [
  "VANILLA",
  "PAPER",
  "PURPUR",
  "FABRIC",
  "FORGE",
  "NEOFORGE",
  "QUILT",
  "BEDROCK_DEDICATED",
] as const;

export function createServerSchema(messages: {
  nameRequired: string;
  nameMax: string;
  planRequired: string;
  planInvalid: string;
  versionRequired: string;
  softwareRequired: string;
  eulaRequired: string;
}) {
  return z.object({
    name: z
      .string()
      .min(1, messages.nameRequired)
      .max(64, messages.nameMax),
    planId: z
      .string()
      .min(1, messages.planRequired)
      .uuid(messages.planInvalid),
    minecraftVersion: z.string().min(1, messages.versionRequired),
    softwareFamily: z.enum(softwareFamilyValues, {
      errorMap: () => ({ message: messages.softwareRequired }),
    }),
    eulaAccepted: z
      .boolean()
      .refine((value) => value === true, { message: messages.eulaRequired }),
  });
}

export type CreateServerFormValues = z.infer<ReturnType<typeof createServerSchema>>;

export const MINECRAFT_VERSIONS = ["1.21.1", "1.21", "1.20.6", "1.20.4"] as const;

export const SOFTWARE_FAMILIES = softwareFamilyValues;
