# Installer High Availability Configuration Fragment

[[elements]]
border_bottom = false
border_top = true
name = "ha_section_header"
title = "🔄 High Availability"
type = "section_header"

# HA Enablement
[[elements]]
default = false
help = "Enable high availability configuration"
name = "ha_enabled"
nickel_path = ["installer", "ha", "enabled"]
prompt = "Enable High Availability"
type = "confirm"

# Cluster Configuration (conditional on HA enabled)
[[elements]]
condition = "ha_enabled == true"
default = 3
help = "Number of nodes in the HA cluster"
max = 256
min = 3
name = "ha_cluster_size"
nickel_path = ["installer", "ha", "cluster_size"]
prompt = "Cluster Size"
type = "number"

[[elements]]
condition = "ha_enabled == true"
default = "consul"
help = "Service discovery backend for cluster coordination"
name = "ha_discovery_backend"
nickel_path = ["installer", "ha", "discovery_backend"]
options = ["consul", "etcd", "zookeeper"]
prompt = "Discovery Backend"
type = "select"

# Cluster Node Configuration (conditional)
[[elements]]
condition = "ha_enabled == true"
default = "replica"
help = "Role of this node in the cluster"
name = "ha_node_role"
nickel_path = ["installer", "ha", "node_role"]
options = ["primary", "replica", "observer"]
prompt = "Node Role"
type = "select"

[[elements]]
condition = "ha_enabled == true"
default = ""
help = "Comma-separated list of other cluster node addresses"
name = "ha_cluster_nodes"
nickel_path = ["installer", "ha", "cluster_nodes"]
prompt = "Cluster Nodes"
type = "text"

# Replication Configuration
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable database replication between cluster nodes"
name = "ha_db_replication_enabled"
nickel_path = ["installer", "ha", "database", "replication_enabled"]
prompt = "Enable DB Replication"
type = "confirm"

[[elements]]
condition = "ha_db_replication_enabled == true"
default = "synchronous"
help = "Database replication mode"
name = "ha_db_replication_mode"
nickel_path = ["installer", "ha", "database", "replication_mode"]
options = ["synchronous", "asynchronous", "semi_synchronous"]
prompt = "DB Replication Mode"
type = "select"

[[elements]]
condition = "ha_enabled == true && ha_db_replication_enabled == true"
default = 3
help = "Minimum quorum size for write operations (range: 1-256)"
max = 256
min = 1
name = "ha_db_quorum_size"
nickel_path = ["installer", "ha", "database", "quorum_size"]
prompt = "DB Quorum Size"
type = "number"

# Health Checks
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable automated health checks for cluster nodes"
name = "ha_health_checks_enabled"
nickel_path = ["installer", "ha", "health_checks", "enabled"]
prompt = "Enable Health Checks"
type = "confirm"

[[elements]]
condition = "ha_health_checks_enabled == true"
default = 10
help = "Health check interval in seconds"
max = 120
min = 1
name = "ha_health_check_interval"
nickel_path = ["installer", "ha", "health_checks", "interval_seconds"]
prompt = "Health Check Interval (seconds)"
type = "number"

[[elements]]
condition = "ha_health_checks_enabled == true"
default = 30000
help = "Health check timeout in milliseconds"
max = 300000
min = 1000
name = "ha_health_check_timeout"
nickel_path = ["installer", "ha", "health_checks", "timeout_ms"]
prompt = "Health Check Timeout (ms)"
type = "number"

[[elements]]
condition = "ha_health_checks_enabled == true"
default = 3
help = "Number of failed checks before marking node as unhealthy"
max = 10
min = 1
name = "ha_health_check_failure_threshold"
nickel_path = ["installer", "ha", "health_checks", "failure_threshold"]
prompt = "Failure Threshold"
type = "number"

# Failover Configuration
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable automatic failover to replica nodes"
name = "ha_failover_enabled"
nickel_path = ["installer", "ha", "failover", "enabled"]
prompt = "Enable Failover"
type = "confirm"

[[elements]]
condition = "ha_failover_enabled == true"
default = "automatic"
help = "Failover strategy"
name = "ha_failover_strategy"
nickel_path = ["installer", "ha", "failover", "strategy"]
options = ["automatic", "manual", "priority_based"]
prompt = "Failover Strategy"
type = "select"

[[elements]]
condition = "ha_failover_enabled == true"
default = 60
help = "Failover delay in seconds (wait before failing over)"
max = 600
min = 0
name = "ha_failover_delay"
nickel_path = ["installer", "ha", "failover", "delay_seconds"]
prompt = "Failover Delay (seconds)"
type = "number"

[[elements]]
condition = "ha_failover_enabled == true && ha_failover_strategy == 'priority_based'"
default = 100
help = "Priority value for node selection in failover (higher = higher priority)"
max = 1000
min = 0
name = "ha_node_priority"
nickel_path = ["installer", "ha", "failover", "node_priority"]
prompt = "Node Priority"
type = "number"

# Split Brain Prevention
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable split-brain detection and prevention"
name = "ha_split_brain_enabled"
nickel_path = ["installer", "ha", "split_brain", "enabled"]
prompt = "Enable Split-Brain Prevention"
type = "confirm"

[[elements]]
condition = "ha_split_brain_enabled == true"
default = 30
help = "Timeout for detecting split-brain in seconds"
max = 300
min = 5
name = "ha_split_brain_timeout"
nickel_path = ["installer", "ha", "split_brain", "timeout_seconds"]
prompt = "Split-Brain Timeout (seconds)"
type = "number"

[[elements]]
condition = "ha_split_brain_enabled == true"
default = "quorum_based"
help = "Split-brain resolution strategy"
name = "ha_split_brain_strategy"
nickel_path = ["installer", "ha", "split_brain", "strategy"]
options = ["quorum_based", "majority_wins", "freeze"]
prompt = "Split-Brain Strategy"
type = "select"

# Backup and Recovery
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable automated cluster state backups"
name = "ha_backup_enabled"
nickel_path = ["installer", "ha", "backup", "enabled"]
prompt = "Enable Backups"
type = "confirm"

[[elements]]
condition = "ha_backup_enabled == true"
default = 3600
help = "Backup interval in seconds (default: 1 hour, range: 300-86400)"
max = 86400
min = 300
name = "ha_backup_interval"
nickel_path = ["installer", "ha", "backup", "interval_seconds"]
prompt = "Backup Interval (seconds)"
type = "number"

[[elements]]
condition = "ha_backup_enabled == true"
default = 7
help = "Backup retention in days"
max = 365
min = 1
name = "ha_backup_retention_days"
nickel_path = ["installer", "ha", "backup", "retention_days"]
prompt = "Backup Retention (days)"
type = "number"

[[elements]]
condition = "ha_backup_enabled == true"
default = "/var/backups/provisioning-ha"
help = "Directory for HA cluster backups"
name = "ha_backup_directory"
nickel_path = ["installer", "ha", "backup", "directory"]
prompt = "Backup Directory"
type = "text"

# Load Distribution
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable load distribution across cluster nodes"
name = "ha_load_distribution_enabled"
nickel_path = ["installer", "ha", "load_distribution", "enabled"]
prompt = "Enable Load Distribution"
type = "confirm"

[[elements]]
condition = "ha_load_distribution_enabled == true"
default = "round_robin"
help = "Load distribution algorithm"
name = "ha_load_distribution_algorithm"
nickel_path = ["installer", "ha", "load_distribution", "algorithm"]
options = ["round_robin", "least_connections", "weighted", "ip_hash"]
prompt = "Load Distribution Algorithm"
type = "select"

# Metrics and Monitoring
[[elements]]
condition = "ha_enabled == true"
default = true
help = "Enable detailed HA metrics collection"
name = "ha_metrics_enabled"
nickel_path = ["installer", "ha", "metrics", "enabled"]
prompt = "Enable Metrics"
type = "confirm"

[[elements]]
condition = "ha_metrics_enabled == true"
default = 60
help = "Metrics collection interval in seconds (range: 5-300)"
max = 300
min = 5
name = "ha_metrics_interval"
nickel_path = ["installer", "ha", "metrics", "interval_seconds"]
prompt = "Metrics Interval (seconds)"
type = "number"
