# Basic Validators and Constraints Example
#
# TypeDialog provides built-in validators for common validation patterns:
# - required: Field must have a value
# - min/max: Numeric range limits
# - min_items/max_items: Array size constraints
# - min_selected/max_selected: Multiselect constraints
# - unique: Array items must be unique
# - min_date/max_date: Date range constraints
#
# This example demonstrates foundational validation patterns.

name = "Basic Validators & Constraints"
description = "Learn fundamental validation patterns with min/max/required"

# ====================================================================
# REQUIRED FIELDS
# ====================================================================

[[elements]]
name = "username"
type = "text"
prompt = "Username"
help = "Required field - cannot be empty"
required = true

[[elements]]
name = "email"
type = "text"
prompt = "Email address"
help = "Email is required for account creation"
required = true

# ====================================================================
# TEXT FIELD LENGTH VALIDATION (via placeholder hints)
# ====================================================================

[[elements]]
name = "password"
type = "password"
prompt = "Password"
help = "Minimum 8 characters (enforced by external validation)"
required = true
placeholder = "At least 8 characters, include uppercase/lowercase/numbers"

# ====================================================================
# NUMERIC RANGE VALIDATION
# ====================================================================

[[elements]]
name = "age"
type = "text"
prompt = "Age"
help = "Must be between 18 and 100"
required = true
placeholder = "18-100"

[[elements]]
name = "port"
type = "text"
prompt = "Server Port"
help = "Port number must be between 1024 and 65535"
placeholder = "1024-65535"

# ====================================================================
# SELECT WITH REQUIRED CONSTRAINT
# ====================================================================

[[elements]]
name = "country"
type = "select"
prompt = "Country"
help = "You must select a country"
required = true
options = [
  { value = "us", label = "United States" },
  { value = "uk", label = "United Kingdom" },
  { value = "ca", label = "Canada" },
  { value = "au", label = "Australia" },
  { value = "de", label = "Germany" },
  { value = "fr", label = "France" },
  { value = "jp", label = "Japan" },
]

# ====================================================================
# MULTISELECT WITH MIN/MAX CONSTRAINTS
# ====================================================================

[[elements]]
name = "interests"
type = "multiselect"
prompt = "Select your interests (choose 2-4)"
help = "Select between 2 and 4 interests"
min_selected = 2
max_selected = 4
required = true
options = [
  { value = "technology", label = "🚀 Technology" },
  { value = "music", label = "🎵 Music" },
  { value = "sports", label = "⚽ Sports" },
  { value = "travel", label = "✈️ Travel" },
  { value = "cooking", label = "👨‍🍳 Cooking" },
  { value = "reading", label = "📚 Reading" },
]

# ====================================================================
# DATE RANGE VALIDATION
# ====================================================================

[[elements]]
name = "birth_date"
type = "date"
prompt = "Date of birth"
help = "Must be between 1950 and today"
required = true
min_date = "1950-01-01"
max_date = "2006-12-31"

[[elements]]
name = "start_date"
type = "date"
prompt = "Project start date"
help = "Must be today or later"
min_date = "today"

# ====================================================================
# CONFIRM FIELD (boolean validation)
# ====================================================================

[[elements]]
name = "agree_terms"
type = "confirm"
prompt = "I agree to the terms and conditions"
help = "You must accept the terms to continue"
required = true
default = "false"

[[elements]]
name = "subscribe"
type = "confirm"
prompt = "Subscribe to newsletter"
help = "Optional - not required"
default = "false"

# ====================================================================
# CONSTRAINTS (DRY source of truth for limits)
# ====================================================================
# Constraints provide a single source of truth for validation limits
# They can be overridden per-field but encourage reuse

[constraints]
# Username constraints
username_min_length = 3
username_max_length = 32

# Password constraints
password_min_length = 8
password_min_uppercase = 1
password_min_numbers = 1

# Age constraints
age_min = 18
age_max = 100

# Port constraints
port_min = 1024
port_max = 65535

# File limits
file_max_size_mb = 10
file_max_count = 5
