#!/bin/bash
set -e

CLI_URL="https://cli.seonology.com/releases"
INSTALL_DIR="/usr/local/bin"

# Detect OS and architecture
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$ARCH" in
  x86_64) ARCH="amd64" ;;
  arm64|aarch64) ARCH="arm64" ;;
  *) echo "Unsupported architecture: $ARCH"; exit 1 ;;
esac

case "$OS" in
  darwin) BINARY="seon-darwin-$ARCH" ;;
  linux) BINARY="seon-linux-amd64" ;;
  *) echo "Unsupported OS: $OS"; exit 1 ;;
esac

echo "Downloading seon CLI..."
curl -sL "$CLI_URL/$BINARY" -o /tmp/seon

echo "Installing to $INSTALL_DIR..."
chmod +x /tmp/seon
sudo mv /tmp/seon "$INSTALL_DIR/seon"

echo "Done! Run 'seon --help' to get started."
echo ""
echo "Next steps:"
echo "  1. Install vault CLI: brew install vault"
echo "  2. Initialize: seon init"
echo "  3. Generate SSH key: ssh-keygen -t ed25519 -f ~/.ssh/vault-ssh -N \"\""
