import * as z from "zod";

export type UploadProjectSchema = {
  name?: string;
  email?: string;
  file?: File[];
  ready?: boolean;
  note?: string;
};

export const getUploadProjectSchema = (dict: Dictionary) => {
  const { project_name, project_file } = dict.pages.project_list.form.fields;

  return z.object({
    name: z
      .string({
        required_error: project_name.errors.required,
      })
      .toLowerCase()
      .min(3, project_name.errors.min_length)
      .max(20, project_name.errors.max_length)
      .refine((value) => {
        return /^[a-zA-Z0-9]+$/.test(value);
      }, project_name.errors.alphanumeric),
    email: z.string().email().optional().or(z.literal("")),
    file: z
      .array(
        z
          .instanceof(File, { message: project_file.errors.type_file })
          .refine(
            (file) => file.name.endsWith(".zip"),
            project_file.errors.zip_file,
          ),
      )
      .length(1, project_file.errors.required),
    ready: z.boolean(),
    note: z.string(),
  });
};
