#!/bin/bash
set -e

# ProofMode Docker Entrypoint Script
# This script provides flexible command execution for the ProofMode container

# Function to display help
show_help() {
    echo "ProofMode Docker Container"
    echo "========================="
    echo ""
    echo "Usage:"
    echo "  docker run proofmode [command] [options]"
    echo ""
    echo "Available commands:"
    echo "  check      - Verify media files"
    echo "  generate   - Create cryptographic proof bundles"
    echo "  sign       - Certificate signing (placeholder)"
    echo "  bash       - Start an interactive bash shell"
    echo "  sh         - Start an interactive sh shell"
    echo ""
    echo "Environment variables:"
    echo "  PROOFMODE_INPUT_DIR   - Input directory (default: /app/input)"
    echo "  PROOFMODE_OUTPUT_DIR  - Output directory (default: /app/output)"
    echo "  PROOFMODE_CONFIG_DIR  - Config directory (default: /app/config)"
    echo "  RUST_LOG              - Logging level (default: info)"
    echo ""
    echo "Examples:"
    echo "  docker run -v /path/to/media:/app/input proofmode check /app/input/photo.jpg"
    echo "  docker run -v /path/to/media:/app/input -v /path/to/output:/app/output proofmode generate /app/input/video.mp4"
    echo ""
}

# Check if no arguments provided
if [ $# -eq 0 ]; then
    show_help
    exit 0
fi

# Handle special commands
case "$1" in
    "help"|"--help"|"-h")
        show_help
        exit 0
        ;;
    "bash")
        exec /bin/bash
        ;;
    "sh")
        exec /bin/sh
        ;;
    "version"|"--version"|"-v")
        exec proofmode --version
        ;;
esac

# Check if the first argument is a proofmode command
if [[ "$1" =~ ^(check|generate|sign)$ ]]; then
    # Execute proofmode with all arguments
    exec proofmode "$@"
else
    # If not a recognized command, pass all arguments to proofmode
    # This allows for direct flag usage like --help, --version, etc.
    exec proofmode "$@"
fi