# syntaxis Provisioning Configuration
#
# This file defines how syntaxis binaries are packaged, distributed, and installed.
# It serves as a single source of truth for the provisioning system.

[version]
provisioning_version = "1.0.0"
created_at = "2025-11-17"

# ==============================================================================
# TARGETS: Platform definitions for packaging
# ==============================================================================
[targets]

# Linux x86_64 (glibc - most common)
[targets.x86_64-unknown-linux-gnu]
enabled = true
os = "linux"
arch = "x86_64"
libc = "glibc"
formats = ["tar.gz", "deb"]
default_prefix = "/usr/local"
description = "Linux x86_64 (glibc)"

# Linux x86_64 (musl - Alpine)
[targets.x86_64-unknown-linux-musl]
enabled = false  # Optional, requires special build
os = "linux"
arch = "x86_64"
libc = "musl"
formats = ["tar.gz"]
default_prefix = "/usr/local"
description = "Linux x86_64 (musl/Alpine)"

# Linux ARM64
[targets.aarch64-unknown-linux-gnu]
enabled = true
os = "linux"
arch = "aarch64"
libc = "glibc"
formats = ["tar.gz", "deb"]
default_prefix = "/usr/local"
description = "Linux ARM64 (glibc)"

# macOS x86_64 (Intel)
[targets.x86_64-apple-darwin]
enabled = true
os = "macos"
arch = "x86_64"
formats = ["tar.gz", "zip"]
default_prefix = "/usr/local"
homebrew_available = true
description = "macOS Intel (x86_64)"

# macOS ARM64 (Apple Silicon - M1/M2/M3)
[targets.aarch64-apple-darwin]
enabled = true
os = "macos"
arch = "aarch64"
formats = ["tar.gz", "zip"]
default_prefix = "/usr/local"
homebrew_available = true
description = "macOS Apple Silicon (ARM64)"

# Windows x86_64 (MSVC)
[targets.x86_64-pc-windows-msvc]
enabled = true
os = "windows"
arch = "x86_64"
formats = ["zip", "exe"]
default_prefix = "C:\\Program Files\\syntaxis"
description = "Windows x86_64 (MSVC)"

# ==============================================================================
# ARTIFACTS: What to include in bundles
# ==============================================================================
[artifacts]

# Binary artifacts
binaries = [
    { name = "syntaxis-cli", crate = "cli", type = "binary", description = "Command-line interface" },
    { name = "syntaxis-tui", crate = "tui", type = "binary", description = "Terminal user interface" },
    { name = "syntaxis-api", crate = "api", type = "binary", description = "REST API server" },
]

# Configuration files
configs = [
    "configs/provisioning.toml",
    "configs/database-default.toml",
    "configs/database-surrealdb.toml",
    "configs/cli/syntaxis-cli.toml",
    "configs/tui/syntaxis-tui.toml",
    "configs/api/syntaxis-api.toml",
    "configs/api/features/auth.toml.template",
    "configs/api/features/database.toml.template",
    "configs/api/features/metrics.toml.template",
    "configs/api/features/logging.toml.template",
]

# Documentation (for bundle users)
# Root level files
docs = [
    "docs/BUNDLE_README.md",         # Bundle overview (becomes README.md at root)
    "docs/INSTALL.md",               # Installation guide (generic, no platform-specific)
    "docs/QUICK_START.md",           # 5-minute getting started guide
    "docs/CONFIG.md",                # Configuration reference for all apps
    "docs/TROUBLESHOOTING.md",       # Common issues and solutions
    "docs/PACK.md",                  # Provisioning system documentation
]

# Installation and setup scripts
scripts = [
    "scripts/provisioning/install.sh",       # Bash installer for offline bundles
    "scripts/provisioning/install.nu",       # NuShell installer (if available)
    "scripts/provisioning/setup-config.sh",  # Interactive configuration helper
]

# Wrapper scripts for auto-config injection during runtime
# These enable the three-layer wrapper architecture:
#   Layer 1: Bash wrapper (sets environment)
#   Layer 2: NuShell wrapper (discovers config, injects --config flag)
#   Layer 3: Real binary (actual compiled executable)
# Result: Users type "syntaxis-cli status" instead of "syntaxis-cli --config path status"
wrapper_scripts = [
    "scripts/syntaxis-lib.nu",               # Shared library for all wrappers
    "scripts/syntaxis-cli.nu",               # CLI auto-config wrapper
    "scripts/syntaxis-cli-lib.nu",           # CLI utilities
    "scripts/syntaxis-tui.nu",               # TUI auto-config wrapper
    "scripts/syntaxis-tui-lib.nu",           # TUI utilities
    "scripts/syntaxis-api.nu",               # API auto-config wrapper
    "scripts/syntaxis-api-lib.nu",           # API utilities
]

# ==============================================================================
# PACKAGING STRATEGIES
# ==============================================================================
[packaging.tar_gz]
enabled = true
format = "tar.gz"
compression = "gzip"
platforms = ["linux", "macos"]
description = "Compressed TAR archive (standard Unix)"

[packaging.zip]
enabled = true
format = "zip"
compression = "deflate"
platforms = ["macos", "windows"]
description = "ZIP archive (Windows compatible)"

[packaging.deb]
enabled = true
format = "deb"
compression = "xz"
platforms = ["linux"]
architecture_mapping = { "x86_64" = "amd64", "aarch64" = "arm64" }
description = "Debian package format"
# Dependencies that deb package should declare
dependencies = ["libsqlite3-0", "ca-certificates"]

[packaging.rpm]
enabled = false  # Optional, requires cargo-generate-rpm
format = "rpm"
compression = "xz"
platforms = ["linux"]
description = "RedHat package format"

[packaging.exe]
enabled = true
format = "exe"
compression = "none"
platforms = ["windows"]
description = "Windows executable installer"

# ==============================================================================
# INSTALLATION STRATEGIES
# ==============================================================================
[installation]

# Default installation prefix per OS
prefix_defaults = { "linux" = "/usr/local", "macos" = "/usr/local", "windows" = "C:\\Program Files\\syntaxis" }

# Environment variables to set
env_vars = { "SYNTAXIS_CONFIG_DIR" = "~/.config/syntaxis", "SYNTAXIS_DATA_DIR" = "~/.local/share/syntaxis" }

# Directories that need to be created
required_dirs = [
    "~/.config/syntaxis",
    "~/.local/share/syntaxis",
    "~/.syntaxis",  # Manifest directory
]

# Post-installation actions
[[post_install]]
action = "create_manifest"
target = "~/.syntaxis/manifest.toml"

[[post_install]]
action = "copy_configs"
source = "configs/"
target = "~/.config/syntaxis/"

[[post_install]]
action = "update_shell_rc"
target = "PATH"

# ==============================================================================
# BUNDLE CONFIGURATION
# ==============================================================================
[bundle]

# How bundle metadata is stored
manifest_file = "manifest.toml"
manifest_format = "toml"

# Generate checksums for verification
generate_checksums = true
checksum_algorithm = "sha256"

# Include installation script in bundle
include_installer = true
installer_format = "bash"  # bash or powershell for Windows

# Bundle layout
layout = { "binaries" = "bin/", "configs" = "configs/", "docs" = "docs/", "scripts" = "scripts/", "manifest" = "./" }

# ==============================================================================
# BUILD CONFIGURATION
# ==============================================================================
[build]

# Build type
release = true          # cargo build --release
all_targets = false     # Don't build examples/tests
verbose = false         # Verbose output

# Optional: Exclude certain features for offline bundles
exclude_features = [
    "surrealdb",  # Optional SurrealDB backend - not in offline bundles
]

# Optimization level
opt_level = 3           # Maximum optimization
lto = "thin"           # Link-time optimization
codegen_units = 1      # Better optimization (slower compilation)

# Features (as table of arrays)
[build.features]
"syntaxis-core" = ["default"]
"syntaxis-cli" = ["default"]
"syntaxis-tui" = ["default"]
"syntaxis-api" = ["default"]

# ==============================================================================
# DISTRIBUTION & DEPLOYMENT
# ==============================================================================
[distribution]

# GitHub integration (optional)
github_repo = "syntaxis/syntaxis"
github_releases_enabled = true

# Output directory for built bundles
output_dir = "dist/"
archive_dir = "archives/"

# Naming convention for bundles
bundle_naming = "{name}-v{version}-{target}.{format}"
# Example: syntaxis-v0.1.0-x86_64-unknown-linux-gnu.tar.gz

# ==============================================================================
# VERIFICATION & INTEGRITY
# ==============================================================================
[verification]

# Verify binaries after download
verify_checksums = true
verify_signatures = false  # Optional: GPG signing

# Size limits (warn if exceeded)
max_bundle_size_mb = 100
warn_if_larger_than_mb = 50

# ==============================================================================
# PROVISIONING COMMANDS - CLI INTERFACE
# ==============================================================================
[commands]

[commands.pack]
description = "Create bundle from built binaries"
script = "scripts/provisioning/pack.nu"
usage = "nu scripts/provisioning/pack.nu --target <TARGET> --output <DIR>"

[commands.unpack]
description = "Extract bundle to filesystem"
script = "scripts/provisioning/unpack.nu"
usage = "nu scripts/provisioning/unpack.nu <BUNDLE> --dest <DIR>"

[commands.install]
description = "Install binaries to system"
script = "scripts/provisioning/install.nu"
usage = "nu scripts/provisioning/install.nu --source <DIR> --prefix <PATH>"

[commands.deploy]
description = "Deploy configuration files"
script = "scripts/provisioning/deploy.nu"
usage = "nu scripts/provisioning/deploy.nu --source <DIR> --config-dir <PATH>"

[commands.provctl]
description = "Orchestrate provisioning operations"
script = "scripts/provisioning/provctl.nu"
usage = "nu scripts/provisioning/provctl.nu <ACTION> [OPTIONS]"
