#!/bin/bash
#
# Shodh Memory Install Script
# Installs npm package and sets up auto-start on macOS
#

set -e

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"

INFO='\033[0;34m'
SUCCESS='\033[0;32m'
WARNING='\033[1;33m'
ERROR='\033[0;31m'
NC='\033[0m'

print_info() { echo -e "${INFO}[INFO]${NC} $1"; }
print_success() { echo -e "${SUCCESS}[OK]${NC} $1"; }
print_warning() { echo -e "${WARNING}[WARN]${NC} $1"; }
print_error() { echo -e "${ERROR}[ERR]${NC} $1"; }

check_dependencies() {
    if ! command -v python3 >/dev/null 2>&1; then
        print_error "python3 is required"
        exit 1
    fi
    print_success "Dependencies checked"
}

install_npm() {
    print_info "Installing shodh-memory Python SDK..."
    
    if pip3 install shodh-memory; then
        print_success "shodh-memory installed"
    else
        print_error "Failed to install shodh-memory"
        exit 1
    fi
}

generate_api_key() {
    print_info "No API key needed - using local storage"
}

create_launchagent() {
    print_info "No auto-start needed - SDK runs on-demand"
}

start_server() {
    print_info "Ready to use!"
}

show_status() {
    echo ""
    echo "=========================================="
    print_success "Shodh Memory Installation Complete!"
    echo "=========================================="
    echo ""
    echo "Usage:"
    echo "  python3 $SCRIPT_DIR/cli.py remember \"text\" --type Decision"
    echo "  python3 $SCRIPT_DIR/cli.py recall \"query\""
    echo "  python3 $SCRIPT_DIR/cli.py stats"
    echo ""
}

main() {
    echo "Shodh Memory Installer"
    echo "======================"
    echo ""
    
    check_dependencies
    install_npm
    show_status
}

main "$@"
