#!/usr/bin/env bash

# 1. If .rust-channel exists, read it; otherwise default to stable
if [ -f .rust-channel ]; then
  RUST_CHANNEL="$(cat .rust-channel)"
else
  RUST_CHANNEL="stable"
fi

# 2. Validate the channel; if it's not "nightly", assume stable
if [ "$RUST_CHANNEL" != "nightly" ]; then
  RUST_CHANNEL="stable"
fi

echo "Selected Rust channel: $RUST_CHANNEL"

# 3. Load the corresponding devShell from the flake
use flake ."#$RUST_CHANNEL"

# Ensure tools/vsa is accessible
PATH_add "$PWD/tools/vsa"

# Define a function instead of an alias
vsa() {
    cargo run --manifest-path tools/vsa/Cargo.toml -- "$@"
}

# Load environment variables from .env file
if [ -f .env ]; then
  set -a
  source .env
  set +a
fi
