import { z } from 'zod';

const baseMetaSchema = z.object({
  label: z.string().min(1).meta({ label: "Label" }),
  description: z.string().optional().meta({ label: "Description" }),
  required: z.boolean().default(false).meta({ label: "Required", fieldType: "switch" })
});
const baseMetaSchemaWithPlaceholder = baseMetaSchema.merge(
  z.object({
    placeholder: z.string().optional().meta({ label: "Placeholder" })
  })
);
const DEFAULT_VALUE_SCHEMAS = {
  string: z.string().optional().meta({ label: "Default Value" }),
  number: z.number().optional().meta({ label: "Default Value" }),
  boolean: z.boolean().default(false).meta({ label: "Default Value", fieldType: "switch" }),
  date: z.date().optional().meta({ label: "Default Date", fieldType: "date" }),
  enum: z.string().optional().meta({
    label: "Default Value",
    description: "Must match one of the options"
  })
};
const stringValidationSchema = z.object({
  minLength: z.number().int().min(0).optional().meta({ label: "Min Length" }),
  maxLength: z.number().int().min(1).optional().meta({ label: "Max Length" })
  // Note: pattern/regex is serializable but requires careful UX for input
  // Uncomment to enable:
  // pattern: z.string().optional().meta({ label: "Pattern (Regex)" }),
});
const numberValidationSchema = z.object({
  min: z.number().optional().meta({ label: "Minimum" }),
  max: z.number().optional().meta({ label: "Maximum" })
  // Note: multipleOf is serializable but less commonly used
  // Uncomment to enable:
  // multipleOf: z.number().optional().meta({ label: "Multiple Of" }),
});
const booleanValidationSchema = z.object({});
const dateValidationSchema = z.object({
  // Date min/max can be added when the date serialization is refined
  // minDate: z.date().optional().meta({ label: "Minimum Date", fieldType: "date" }),
  // maxDate: z.date().optional().meta({ label: "Maximum Date", fieldType: "date" }),
});
const enumOptionsSchema = z.object({
  options: z.string().meta({
    label: "Options (one per line)",
    fieldType: "textarea",
    description: "Enter each option on a new line"
  })
});
const objectValidationSchema = z.object({});
const arrayValidationSchema = z.object({
  minItems: z.number().int().min(0).optional().meta({ label: "Min Items" }),
  maxItems: z.number().int().min(1).optional().meta({ label: "Max Items" })
});

export { DEFAULT_VALUE_SCHEMAS, arrayValidationSchema, baseMetaSchema, baseMetaSchemaWithPlaceholder, booleanValidationSchema, dateValidationSchema, enumOptionsSchema, numberValidationSchema, objectValidationSchema, stringValidationSchema };
