# syntaxis Installation Configuration
#
# This file defines installation presets, database backends, and service configurations.
# It serves as the source of truth for the enhanced installer system.
#
# Usage:
#   nu scripts/install-syntaxis.nu --preset local
#   nu scripts/install-syntaxis.nu --preset dev
#   nu scripts/install-syntaxis.nu --config my-install.toml

[version]
installation_config_version = "1.0.0"
created_at = "2025-11-19"

# ==============================================================================
# DEFAULT INSTALLATION SETTINGS
# ==============================================================================
[defaults]
# Default preset if not specified
preset = "local"

# provctl integration mode
# - "auto": Use provctl if available, fallback to manual setup
# - "required": Fail if provctl not available (for advanced presets)
# - "disabled": Never use provctl (manual setup only)
provctl_mode = "auto"

# Interactive mode (ask user questions during installation)
interactive = false

# Generate installation config without installing
generate_config_only = false

# ==============================================================================
# INSTALLATION PRESETS
# ==============================================================================

# Preset: MINIMAL (ultra-lightweight, CLI only)
# Perfect for: Embedded systems, CI/CD agents, headless servers
[preset.minimal]
name = "Minimal (CLI Only)"
description = "Ultra-lightweight setup - CLI tool only, no TUI/API/Dashboard"
database_backend = "sqlite"
surrealdb_mode = "none"
auto_start_services = false
provctl_required = false
contexts = ["cli-only", "embedded", "headless", "minimal-overhead"]

[preset.minimal.services]
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = false }
syntaxis_api = { enabled = false }
dashboard = { enabled = false }
surrealdb = { enabled = false }
nats = { enabled = false }

[preset.minimal.notes]
setup_time = "~3 minutes (CLI only)"
prerequisites = ["Rust toolchain (for building)"]
next_step = "Run: syntaxis-cli init my-project"
use_cases = ["CI/CD agents", "Embedded systems", "Server-side only", "Minimal footprint"]

# Preset: LOCAL (default - simple development on laptop)
# Minimal setup: SQLite, no external services, binaries only
[preset.local]
name = "Local Development"
description = "Simple development setup on laptop - SQLite only, no external services"
database_backend = "sqlite"
surrealdb_mode = "none"
auto_start_services = false
provctl_required = false
contexts = ["single-user", "offline-friendly", "minimal-setup"]

[preset.local.services]
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = true, auto_start = false }
syntaxis_api = { enabled = false, auto_start = false }
dashboard = { enabled = false, auto_start = false }
surrealdb = { enabled = false, auto_start = false }
nats = { enabled = false, auto_start = false }

[preset.local.notes]
setup_time = "~5 minutes (binaries only)"
prerequisites = ["Rust toolchain (for building)"]
next_step = "Run: cargo build --release"

# Preset: DEV (development with services)
# Full services: SurrealDB server mode, NATS, syntaxis API, dashboard
[preset.dev]
name = "Development with Services"
description = "Development setup with local SurrealDB server, NATS, API and dashboard"
database_backend = "surrealdb"
surrealdb_mode = "server"
surrealdb_url = "ws://127.0.0.1:8000"
auto_start_services = true
provctl_required = false
provctl_recommended = true
contexts = ["multi-service", "local-development", "testing"]

[preset.dev.services]
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = true, auto_start = false }
syntaxis_api = { enabled = true, auto_start = true, port = 3000 }
dashboard = { enabled = true, auto_start = true, port = 8080 }
surrealdb = { enabled = true, auto_start = true, port = 8000, mode = "server" }
nats = { enabled = true, auto_start = true, port = 4222 }

[preset.dev.notes]
setup_time = "~10-15 minutes (with service setup)"
prerequisites = ["Rust toolchain", "SurrealDB CLI (optional: provctl)", "Docker (optional)"]
next_step = "Run: provctl start surrealdb && provctl start nats"

# Preset: STAGING (integration/CI-CD environment)
# Docker-based: SurrealDB in Docker, NATS, API, monitoring
[preset.staging]
name = "Staging/CI-CD"
description = "Staging environment with Docker services, monitoring, and health checks"
database_backend = "surrealdb"
surrealdb_mode = "docker"
surrealdb_url = "ws://surrealdb:8000"
auto_start_services = true
provctl_required = false
provctl_recommended = true
contexts = ["containerized", "ci-cd", "monitoring"]

[preset.staging.services]
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = true, auto_start = false }
syntaxis_api = { enabled = true, auto_start = true, port = 3000 }
dashboard = { enabled = true, auto_start = true, port = 8080 }
surrealdb = { enabled = true, auto_start = true, port = 8000, mode = "docker", image = "surrealdb/surrealdb:latest" }
nats = { enabled = true, auto_start = true, port = 4222, mode = "docker", image = "nats:2.10-alpine" }
prometheus = { enabled = true, auto_start = true, port = 9090 }

[preset.staging.notes]
setup_time = "~20 minutes (with Docker setup)"
prerequisites = ["Docker", "Docker Compose", "provctl (recommended)"]
next_step = "Run: docker-compose -f docker/docker-compose.yml up"

# Preset: PRODUCTION (Kubernetes/managed deployment)
# Kubernetes-based: SurrealDB cluster, NATS cluster, TLS, monitoring
[preset.production]
name = "Production"
description = "Production deployment with Kubernetes, TLS, clustering, and enterprise monitoring"
database_backend = "surrealdb"
surrealdb_mode = "kubernetes"
surrealdb_url = "ws://surrealdb.syntaxis.svc.cluster.local:8000"
auto_start_services = false  # Managed by Kubernetes
provctl_required = false
provctl_recommended = false  # Kubernetes manages services
contexts = ["kubernetes", "high-availability", "enterprise"]

[preset.production.services]
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = true, auto_start = false }
syntaxis_api = { enabled = true, auto_start = false, replicas = 3, port = 3000 }
dashboard = { enabled = true, auto_start = false, replicas = 2, port = 8080 }
surrealdb = { enabled = true, auto_start = false, replicas = 3, port = 8000, mode = "kubernetes" }
nats = { enabled = true, auto_start = false, replicas = 3, port = 4222, mode = "kubernetes" }
prometheus = { enabled = true, auto_start = false, port = 9090 }
grafana = { enabled = true, auto_start = false, port = 3001 }

[preset.production.notes]
setup_time = "~30-60 minutes (with K8s setup)"
prerequisites = ["Kubernetes cluster", "kubectl", "Helm (optional)", "TLS certificates"]
next_step = "Run: kubectl apply -f kubernetes/"

# Preset: CUSTOM (user-defined configuration)
# Perfect for: Advanced users, custom requirements, special deployments
[preset.custom]
name = "Custom (User-Defined)"
description = "Fully customizable preset - define your own database, services, and configuration"
database_backend = "sqlite"  # Override this value
surrealdb_mode = "none"
auto_start_services = false
provctl_required = false
provctl_recommended = false
contexts = ["custom", "advanced", "user-defined"]

[preset.custom.services]
# Customize services below - enable/disable as needed
syntaxis_cli = { enabled = true, auto_start = false }
syntaxis_tui = { enabled = true, auto_start = false }
syntaxis_api = { enabled = false, auto_start = false, port = 3000 }
dashboard = { enabled = false, auto_start = false, port = 8080 }
surrealdb = { enabled = false, auto_start = false, port = 8000 }
nats = { enabled = false, auto_start = false, port = 4222 }

[preset.custom.notes]
setup_time = "~15-30 minutes (varies)"
prerequisites = ["Depends on your custom configuration"]
next_step = "Edit preset.custom in configs/installation.toml to your needs, then re-run installer"
use_cases = ["Advanced users", "Custom deployments", "Special infrastructure", "Hybrid setups"]
documentation = "docs/INSTALLATION_CONTEXTS.md#custom-preset"

# ==============================================================================
# DATABASE CONFIGURATION
# ==============================================================================

[database.sqlite]
engine = "sqlite"
description = "Local SQLite database"
path = "~/.local/share/core/workspace.db"
max_connections = 5
timeout_secs = 30
wal_mode = true
pragma_synchronous = "NORMAL"
pragma_cache_size = 2000

[database.surrealdb.server]
engine = "surrealdb"
mode = "server"
description = "SurrealDB server mode (local)"
url = "ws://127.0.0.1:8000"
namespace = "syntaxis"
database = "projects"
max_connections = 10
timeout_secs = 60
health_check_interval_secs = 5

[database.surrealdb.docker]
engine = "surrealdb"
mode = "docker"
description = "SurrealDB via Docker Compose"
url = "ws://surrealdb:8000"
namespace = "syntaxis"
database = "projects"
docker_image = "surrealdb/surrealdb:latest"
docker_port = 8000

[database.surrealdb.kubernetes]
engine = "surrealdb"
mode = "kubernetes"
description = "SurrealDB in Kubernetes cluster"
url = "ws://surrealdb.syntaxis.svc.cluster.local:8000"
namespace = "syntaxis"
database = "projects"
replicas = 3

# ==============================================================================
# SERVICE DEFINITIONS
# ==============================================================================

[services.syntaxis-api]
name = "syntaxis-api"
binary = "syntaxis-api"
description = "REST API server for syntaxis"
default_port = 3000
requires_database = true
health_check = { type = "http", endpoint = "/health", interval_secs = 10 }

[services.surrealdb]
name = "surrealdb"
binary = "surreal"
description = "SurrealDB database server"
default_port = 8000
is_database = true
health_check = { type = "tcp", address = "127.0.0.1:8000", interval_secs = 5 }

[services.nats]
name = "nats"
binary = "nats-server"
description = "NATS message broker for agent communication"
default_port = 4222
health_check = { type = "tcp", address = "127.0.0.1:4222", interval_secs = 5 }

[services.dashboard]
name = "dashboard"
binary = "syntaxis-api"  # Served by API
description = "Web dashboard for syntaxis"
default_port = 8080
requires_api = true
health_check = { type = "http", endpoint = "/", interval_secs = 10 }

# ==============================================================================
# FALLBACK BEHAVIOR (when provctl is not available)
# ==============================================================================

[fallback]
# Generate setup guides for manual configuration
generate_setup_guides = true

# Detect and use available service managers
detect_systemd = true
detect_launchd = true

# Provide Docker Compose files as alternative
provide_docker_compose = true

# Create installation manifest with manual steps
create_manual_manifest = true

# ==============================================================================
# MANIFEST & TRACKING
# ==============================================================================

[manifest]
# Where to store installation metadata
location = ".syntaxis/manifest.toml"

# What to track in manifest
track_preset_used = true
track_provctl_status = true
track_installed_services = true
track_database_backend = true
track_timestamps = true

# ==============================================================================
# NOTES & DOCUMENTATION
# ==============================================================================

[notes]
# When to show installation tips
show_tips_on_success = true
show_next_steps = true

# Documentation links
doc_installation_contexts = "docs/INSTALLATION_CONTEXTS.md"
doc_provisioning = "PROVISIONING_GUIDE.md"
doc_surrealdb = "SURREALDB_SETUP_GUIDE.md"
doc_docker = "docker/README.md"
doc_kubernetes = "kubernetes/README.md"
