'use strict';

const z = require('zod');

const baseMetaSchema = z.z.object({
  label: z.z.string().min(1).meta({ label: "Label" }),
  description: z.z.string().optional().meta({ label: "Description" }),
  required: z.z.boolean().default(false).meta({ label: "Required", fieldType: "switch" })
});
const baseMetaSchemaWithPlaceholder = baseMetaSchema.merge(
  z.z.object({
    placeholder: z.z.string().optional().meta({ label: "Placeholder" })
  })
);
const DEFAULT_VALUE_SCHEMAS = {
  string: z.z.string().optional().meta({ label: "Default Value" }),
  number: z.z.number().optional().meta({ label: "Default Value" }),
  boolean: z.z.boolean().default(false).meta({ label: "Default Value", fieldType: "switch" }),
  date: z.z.date().optional().meta({ label: "Default Date", fieldType: "date" }),
  enum: z.z.string().optional().meta({
    label: "Default Value",
    description: "Must match one of the options"
  })
};
const stringValidationSchema = z.z.object({
  minLength: z.z.number().int().min(0).optional().meta({ label: "Min Length" }),
  maxLength: z.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.z.object({
  min: z.z.number().optional().meta({ label: "Minimum" }),
  max: z.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.z.object({});
const dateValidationSchema = z.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.z.object({
  options: z.z.string().meta({
    label: "Options (one per line)",
    fieldType: "textarea",
    description: "Enter each option on a new line"
  })
});
const objectValidationSchema = z.z.object({});
const arrayValidationSchema = z.z.object({
  minItems: z.z.number().int().min(0).optional().meta({ label: "Min Items" }),
  maxItems: z.z.number().int().min(1).optional().meta({ label: "Max Items" })
});

exports.DEFAULT_VALUE_SCHEMAS = DEFAULT_VALUE_SCHEMAS;
exports.arrayValidationSchema = arrayValidationSchema;
exports.baseMetaSchema = baseMetaSchema;
exports.baseMetaSchemaWithPlaceholder = baseMetaSchemaWithPlaceholder;
exports.booleanValidationSchema = booleanValidationSchema;
exports.dateValidationSchema = dateValidationSchema;
exports.enumOptionsSchema = enumOptionsSchema;
exports.numberValidationSchema = numberValidationSchema;
exports.objectValidationSchema = objectValidationSchema;
exports.stringValidationSchema = stringValidationSchema;
