'use strict';

const z = require('zod');

const listFormsQuerySchema = z.z.object({
  status: z.z.enum(["active", "inactive", "archived"]).optional(),
  limit: z.z.coerce.number().min(1).max(100).optional().default(20),
  offset: z.z.coerce.number().min(0).optional().default(0)
});
const createFormSchema = z.z.object({
  name: z.z.string().min(1, "Name is required"),
  slug: z.z.string().min(1, "Slug is required"),
  description: z.z.string().optional(),
  schema: z.z.string().min(1, "Schema is required"),
  successMessage: z.z.string().optional(),
  redirectUrl: z.z.string().url().optional().or(z.z.literal("")),
  status: z.z.enum(["active", "inactive", "archived"]).optional().default("active")
});
const updateFormSchema = z.z.object({
  name: z.z.string().min(1, "Name is required").optional(),
  slug: z.z.string().min(1, "Slug is required").optional(),
  description: z.z.string().optional(),
  schema: z.z.string().min(1, "Schema is required").optional(),
  successMessage: z.z.string().optional(),
  redirectUrl: z.z.string().url().optional().or(z.z.literal("")),
  status: z.z.enum(["active", "inactive", "archived"]).optional()
});
const formResponseSchema = z.z.object({
  id: z.z.string(),
  name: z.z.string(),
  slug: z.z.string(),
  description: z.z.string().nullable().optional(),
  schema: z.z.string(),
  successMessage: z.z.string().nullable().optional(),
  redirectUrl: z.z.string().nullable().optional(),
  status: z.z.string(),
  createdBy: z.z.string().nullable().optional(),
  createdAt: z.z.string(),
  updatedAt: z.z.string()
});
z.z.object({
  items: z.z.array(formResponseSchema),
  total: z.z.number(),
  limit: z.z.number(),
  offset: z.z.number()
});
const listSubmissionsQuerySchema = z.z.object({
  limit: z.z.coerce.number().min(1).max(100).optional().default(20),
  offset: z.z.coerce.number().min(0).optional().default(0)
});
z.z.object({
  // Use passthrough object for dynamic form data validation
  data: z.z.object({}).passthrough()
});
const formSubmissionResponseSchema = z.z.object({
  id: z.z.string(),
  formId: z.z.string(),
  data: z.z.string(),
  submittedAt: z.z.string(),
  submittedBy: z.z.string().nullable().optional(),
  ipAddress: z.z.string().nullable().optional(),
  userAgent: z.z.string().nullable().optional()
});
const formSubmissionWithDataResponseSchema = formSubmissionResponseSchema.extend({
  // Use passthrough object for dynamic parsed data
  parsedData: z.z.object({}).passthrough(),
  form: formResponseSchema.optional()
});
z.z.object({
  items: z.z.array(formSubmissionWithDataResponseSchema),
  total: z.z.number(),
  limit: z.z.number(),
  offset: z.z.number()
});

exports.createFormSchema = createFormSchema;
exports.formResponseSchema = formResponseSchema;
exports.formSubmissionResponseSchema = formSubmissionResponseSchema;
exports.formSubmissionWithDataResponseSchema = formSubmissionWithDataResponseSchema;
exports.listFormsQuerySchema = listFormsQuerySchema;
exports.listSubmissionsQuerySchema = listSubmissionsQuerySchema;
exports.updateFormSchema = updateFormSchema;
