# Conditional Validators - Smart Field Visibility and Requirements
#
# Use the `when` clause to show/hide fields based on other field values.
# Fields shown conditionally can also have their own validation rules.
#
# This example demonstrates:
# - Conditional field visibility (when clause)
# - Conditional requirements (when + required)
# - Cascading conditions (multiple levels)
# - Smart defaults based on conditions

name = "Conditional Validators"
description = "Master field visibility and conditional requirements"

# ====================================================================
# SECTION 1: Account Type Selection
# ====================================================================

[[elements]]
name = "account_type"
type = "select"
prompt = "Account Type"
help = "Choose your account type (all types require different details)"
required = true
default = "personal"
options = [
  { value = "personal", label = "👤 Personal" },
  { value = "business", label = "🏢 Business" },
  { value = "nonprofit", label = "🤝 Non-profit" },
  { value = "education", label = "🎓 Education" },
]

# ====================================================================
# SECTION 2: Personal Account Fields
# ====================================================================

[[elements]]
name = "first_name"
type = "text"
prompt = "First name"
help = "Your first name"
when = "account_type == personal || account_type == education"
required = true
placeholder = "John"

[[elements]]
name = "last_name"
type = "text"
prompt = "Last name"
help = "Your last name"
when = "account_type == personal || account_type == education"
required = true
placeholder = "Doe"

# ====================================================================
# SECTION 3: Business Account Fields
# ====================================================================

[[elements]]
name = "company_name"
type = "text"
prompt = "Company name"
help = "Official company name (required for business accounts)"
when = "account_type == business || account_type == nonprofit"
required = true
placeholder = "Acme Corporation"

[[elements]]
name = "company_type"
type = "select"
prompt = "Company type"
help = "Type of organization"
when = "account_type == business"
required = true
options = [
  { value = "startup", label = "Startup" },
  { value = "scaleup", label = "Scale-up" },
  { value = "enterprise", label = "Enterprise" },
  { value = "agency", label = "Agency" },
  { value = "consulting", label = "Consulting" },
]

[[elements]]
name = "business_registration_number"
type = "text"
prompt = "Business registration number"
help = "Required for business accounts"
when = "account_type == business"
required = true
placeholder = "12345678"

[[elements]]
name = "tax_id"
type = "text"
prompt = "Tax ID / VAT Number"
help = "For invoicing purposes"
when = "account_type == business"
placeholder = "US-TAX-123456"

# ====================================================================
# SECTION 4: Non-profit Specific Fields
# ====================================================================

[[elements]]
name = "nonprofit_category"
type = "select"
prompt = "Non-profit category"
help = "Category of non-profit organization"
when = "account_type == nonprofit"
required = true
options = [
  { value = "charity", label = "Charity" },
  { value = "educational", label = "Educational" },
  { value = "healthcare", label = "Healthcare" },
  { value = "environmental", label = "Environmental" },
  { value = "other", label = "Other" },
]

[[elements]]
name = "nonprofit_registration"
type = "text"
prompt = "Non-profit registration number"
help = "Government registration number"
when = "account_type == nonprofit"
required = true
placeholder = "EIN-12-3456789"

# ====================================================================
# SECTION 5: Education Account Fields
# ====================================================================

[[elements]]
name = "institution_name"
type = "text"
prompt = "Institution name"
help = "Name of your school or university"
when = "account_type == education"
required = true
placeholder = "University of California"

[[elements]]
name = "institution_role"
type = "select"
prompt = "Your role"
help = "Your role at the institution"
when = "account_type == education"
required = true
options = [
  { value = "student", label = "Student" },
  { value = "faculty", label = "Faculty" },
  { value = "staff", label = "Staff" },
  { value = "admin", label = "Administrator" },
]

[[elements]]
name = "student_id"
type = "text"
prompt = "Student ID"
help = "Your student identification number"
when = "account_type == education && institution_role == student"
required = true
placeholder = "SID-123456"

# ====================================================================
# SECTION 6: Universal Account Fields
# ====================================================================

[[elements]]
name = "email"
type = "text"
prompt = "Email address"
help = "Required for all account types"
required = true
placeholder = "email@example.com"

[[elements]]
name = "phone"
type = "text"
prompt = "Phone number"
help = "Optional contact number"
placeholder = "+1 (555) 123-4567"

# ====================================================================
# SECTION 7: Authentication & Security
# ====================================================================

[[elements]]
name = "enable_2fa"
type = "confirm"
prompt = "Enable two-factor authentication"
help = "Add an extra layer of security"
default = "false"

[[elements]]
name = "2fa_method"
type = "select"
prompt = "Two-factor authentication method"
help = "Choose your preferred 2FA method"
when = "enable_2fa == true"
required = true
options = [
  { value = "email", label = "📧 Email" },
  { value = "sms", label = "📱 SMS" },
  { value = "authenticator", label = "🔐 Authenticator App" },
  { value = "security_key", label = "🔑 Security Key" },
]

[[elements]]
name = "backup_email"
type = "text"
prompt = "Backup email"
help = "For account recovery (required if SMS 2FA is chosen)"
when = "2fa_method == sms"
required = true
placeholder = "backup@example.com"

[[elements]]
name = "phone_for_2fa"
type = "text"
prompt = "Phone number for 2FA"
help = "Phone number to receive SMS codes"
when = "2fa_method == sms"
required = true
placeholder = "+1 (555) 123-4567"

# ====================================================================
# SECTION 8: Nested Conditional Validation (3 levels)
# ====================================================================

[[elements]]
name = "enable_api"
type = "confirm"
prompt = "Enable API access"
help = "Allow API connections"
default = "false"

[[elements]]
name = "api_type"
type = "select"
prompt = "API type"
help = "Choose API authentication method"
when = "enable_api == true"
required = true
options = [
  { value = "oauth2", label = "OAuth 2.0" },
  { value = "apikey", label = "API Key" },
  { value = "jwt", label = "JWT Token" },
  { value = "mutual_tls", label = "Mutual TLS" },
]

[[elements]]
name = "oauth2_client_id"
type = "text"
prompt = "OAuth 2.0 Client ID"
help = "Your OAuth2 client identifier"
when = "enable_api == true && api_type == oauth2"
required = true
placeholder = "client_abc123"

[[elements]]
name = "oauth2_client_secret"
type = "password"
prompt = "OAuth 2.0 Client Secret"
help = "Keep this secret safe"
when = "enable_api == true && api_type == oauth2"
required = true
placeholder = "secret_xyz789"

[[elements]]
name = "api_key"
type = "password"
prompt = "API Key"
help = "Your API authentication key"
when = "enable_api == true && api_type == apikey"
required = true
placeholder = "sk-123456789abcdef"

# ====================================================================
# SECTION 9: Terms and Conditions
# ====================================================================

[[elements]]
name = "agree_terms"
type = "confirm"
prompt = "I agree to the terms of service"
help = "You must accept to proceed"
required = true
default = "false"

[[elements]]
name = "subscribe_newsletter"
type = "confirm"
prompt = "Subscribe to our newsletter"
help = "Optional - get updates and offers"
when = "agree_terms == true"
default = "false"

[[elements]]
name = "newsletter_frequency"
type = "select"
prompt = "Newsletter frequency"
help = "How often to receive newsletters"
when = "agree_terms == true && subscribe_newsletter == true"
required = true
default = "weekly"
options = [
  { value = "daily", label = "📅 Daily" },
  { value = "weekly", label = "📆 Weekly" },
  { value = "monthly", label = "🗓️ Monthly" },
  { value = "quarterly", label = "📊 Quarterly" },
]
