#!/bin/bash
# Kimi Development Helper Script

set -e

cd "$(dirname "$0")/../.."

show_help() {
    echo "Kimi Development Helpers"
    echo ""
    echo "Usage: bash .kimi/scripts/dev.sh [command]"
    echo ""
    echo "Commands:"
    echo "  status      Show project status"
    echo "  test        Run tests (unit only, fast)"
    echo "  test-full   Run full test suite"
    echo "  lint        Check code quality"
    echo "  format      Auto-format code"
    echo "  clean       Clean build artifacts"
    echo "  nuke        Full reset (kill port 8000, clean caches)"
    echo "  help        Show this help"
}

cmd_status() {
    echo "=== Kimi Development Status ==="
    echo ""
    echo "Branch: $(git branch --show-current)"
    echo "Last commit: $(git log --oneline -1)"
    echo ""
    echo "Modified files:"
    git status --short
    echo ""
    echo "Ollama: $(curl -s http://localhost:11434/api/tags &>/dev/null && echo "✅ Running" || echo "❌ Not running")"
    echo "Dashboard: $(curl -s http://localhost:8000/health &>/dev/null && echo "✅ Running" || echo "❌ Not running")"
}

cmd_test() {
    echo "Running unit tests..."
    tox -e unit -q
}

cmd_test_full() {
    echo "Running full test suite..."
    make test
}

cmd_lint() {
    echo "Running linters..."
    tox -e lint
}

cmd_format() {
    echo "Auto-formatting code..."
    tox -e format
}

cmd_clean() {
    echo "Cleaning build artifacts..."
    make clean
}

cmd_nuke() {
    echo "Nuking development environment..."
    make nuke
}

# Main
case "${1:-status}" in
    status)
        cmd_status
        ;;
    test)
        cmd_test
        ;;
    test-full)
        cmd_test_full
        ;;
    lint)
        cmd_lint
        ;;
    format)
        cmd_format
        ;;
    clean)
        cmd_clean
        ;;
    nuke)
        cmd_nuke
        ;;
    help|--help|-h)
        show_help
        ;;
    *)
        echo "Unknown command: $1"
        show_help
        exit 1
        ;;
esac
