#!/bin/bash

# Maat Journal Decryption Tool - Installation Script
# This script creates a virtual environment and installs all dependencies

set -e

echo "Maat Journal Decryption Tool - Installation"
echo "==========================================="

# Check if Python is installed
if ! command -v python3 &> /dev/null; then
    echo "ERROR: Python 3 is not installed"
    echo "Please install Python 3.9 or higher first"
    exit 1
fi

# Check if venv module is available
if ! python3 -c "import venv" 2>/dev/null; then
    echo "ERROR: Python venv module not available"
    echo "Install it with: sudo apt install python3-venv"
    exit 1
fi

# Remove existing venv if it exists
if [ -d "venv" ]; then
    echo "Removing existing virtual environment..."
    rm -rf venv
fi

# Create virtual environment
echo "Creating virtual environment..."
python3 -m venv venv

# Activate virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Upgrade pip
echo "Upgrading pip..."
pip install --upgrade pip

# Install dependencies
echo "Installing dependencies..."
pip install python-dotenv mnemonic pycryptodome

echo ""
echo "Installation completed successfully!"
echo ""
echo "To use the decryption tool:"
echo "1. Activate the virtual environment:"
echo "   source venv/bin/activate"
echo ""
echo "2. Create a .env file with your recovery phrase:"
echo "   echo 'RECOVERY_PHRASE=\"your 12 words here\"' > .env"
echo ""
echo "3. Run the decryption tool:"
echo "   python maat_decrypt.py --input your_export.json"
echo ""
echo "To deactivate the virtual environment:"
echo "   deactivate"
