#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────
#  klawd-code — Registry Claim Script (v0.1.0)
#  Secures the "klawd-code" name on Crates.io and npm.
# ──────────────────────────────────────────────────────────
set -euo pipefail

BOLD='\033[1m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
RED='\033[0;31m'
RESET='\033[0m'

banner() { echo -e "\n${CYAN}${BOLD}▸ $1${RESET}\n"; }
success() { echo -e "${GREEN}✔ $1${RESET}"; }
fail()    { echo -e "${RED}✖ $1${RESET}"; exit 1; }

# ── Step 1: Verify Rust compilation ──────────────────────
banner "Step 1/5 — cargo check"
cargo check || fail "cargo check failed. Fix compilation errors first."
success "Crate compiles cleanly."

# ── Step 2: Run tests ───────────────────────────────────
banner "Step 2/5 — cargo test"
cargo test || fail "Tests failed. Fix before publishing."
success "All tests pass."

# ── Step 3: Login to Crates.io ───────────────────────────
banner "Step 3/5 — cargo login"
echo "Paste your API token from https://crates.io/settings/tokens"
cargo login
success "Authenticated with Crates.io."

# ── Step 4: Login to npm ────────────────────────────────
banner "Step 4/5 — npm login"
npm login
success "Authenticated with npm."

# ── Step 5: Publish both ────────────────────────────────
banner "Step 5/5 — Publishing placeholders"

echo -e "${BOLD}Publishing to Crates.io...${RESET}"
cargo publish || fail "cargo publish failed."
success "klawd-code claimed on Crates.io!"

echo ""
echo -e "${BOLD}Publishing to npm...${RESET}"
npm publish || fail "npm publish failed."
success "klawd-code claimed on npm!"

# ── Done ────────────────────────────────────────────────
echo ""
echo -e "${GREEN}${BOLD}══════════════════════════════════════════${RESET}"
echo -e "${GREEN}${BOLD}  ✔ klawd-code v0.1.0 claimed on both    ${RESET}"
echo -e "${GREEN}${BOLD}    registries. Name is SECURED.           ${RESET}"
echo -e "${GREEN}${BOLD}══════════════════════════════════════════${RESET}"
