#!/bin/bash
# ============================================
# Docker Auto Command Implementation
# Called when user runs /docker-auto
# ============================================

# Use the daemon script for all operations
DAEMON_SCRIPT=".claude/scripts/docker-auto-daemon.sh"

# Handle command arguments
case "${1:-status}" in
    start)
        echo "🚀 Starting Docker auto-update..."
        bash "$DAEMON_SCRIPT" start

        # Store in memory that auto-update is active
        echo "AUTO_UPDATE_ACTIVE=true" > /tmp/docker-auto-memory
        ;;

    stop)
        echo "🛑 Stopping Docker auto-update..."
        bash "$DAEMON_SCRIPT" stop

        # Update memory state
        echo "AUTO_UPDATE_ACTIVE=false" > /tmp/docker-auto-memory
        ;;

    status)
        bash "$DAEMON_SCRIPT" status
        ;;

    config)
        bash "$DAEMON_SCRIPT" config
        ;;

    restart)
        echo "🔄 Restarting Docker auto-update..."
        bash "$DAEMON_SCRIPT" restart
        ;;

    logs)
        bash "$DAEMON_SCRIPT" logs
        ;;

    *)
        cat << EOF
Docker Auto-Update Manager
==========================

Usage: /docker-auto [command]

Commands:
  start    - Start automatic Docker updates
  stop     - Stop automatic Docker updates
  status   - Check current status
  config   - Show configuration
  restart  - Restart the daemon
  logs     - View daemon logs

Current features:
  ✓ Hot reload for JS/TS/CSS (instant)
  ✓ Auto-rebuild for Dockerfile/package.json (30-60s)
  ✓ Auto-restart for .env changes (5-10s)

The daemon runs in the background and automatically:
1. Monitors file changes in ./mawidi-site
2. Triggers appropriate Docker updates
3. Maintains logs at /tmp/docker-auto-daemon.log

EOF
        # Show current status
        bash "$DAEMON_SCRIPT" status
        ;;
esac