/**
 * Form Types
 */

// Available form field types
export type FormFieldType =
  | 'text'
  | 'email'
  | 'number'
  | 'password'
  | 'textarea'
  | 'richtext'
  | 'select'
  | 'multiselect'
  | 'date'
  | 'datetime'
  | 'boolean'
  | 'switch'
  | 'image'
  | 'file'
  | 'enum';

// Form field configuration for generic form rendering
export interface FormFieldConfig {
  name: string;
  label: string;
  type: FormFieldType;
  required?: boolean;
  placeholder?: string;
  // For select/multiselect fields - entity endpoint to fetch options from
  itemRef?: string;
  // For select/multiselect fields - field to display from fetched options
  showField?: string;
  // For enum selects - available options
  options?: EnumOption[];
  // For file/image fields - upload path
  uploadPath?: string;
  // For file/image fields - schema constraints
  fileSchema?: FileSchema;
  // For number fields - min/max constraints
  min?: number;
  max?: number;
  // For text fields - max length
  maxLength?: number;
  // Custom className for the field
  className?: string;
}

// Enum option for select dropdowns
export interface EnumOption {
  value: string;
  label: string;
}

// File upload schema constraints
export interface FileSchema {
  size?: number; // max size in bytes
  formats?: string[]; // allowed file extensions
}

// Form page configuration for factory
export interface FormPageConfig<TFormData> {
  entityName: string;
  entityTitle: string;
  mode: 'create' | 'edit';
  permission: string;
  initialValues: TFormData;
  fields: FormFieldConfig[];
  listPath?: string; // Path to navigate after submit
}

// Form submit handler type
export type FormSubmitHandler<T> = (values: T) => Promise<void>;

// Formik-compatible form values (record of field names to values)
export type FormValues = Record<string, unknown>;
