#!/bin/bash

# WAGW SaaS Cleanup Helper

set -e

echo "🧹 WAGW SaaS Cleanup Helper"
echo "=========================="

show_help() {
    echo ""
    echo "Usage: cleanup.sh [command]"
    echo ""
    echo "Commands:"
    echo "  all          Full cleanup (cache, logs, temp)"
    echo "  cache        Clear all caches"
    echo "  logs         Clear old logs"
    echo "  temp         Clear temporary files"
    echo "  help         Show this help message"
    echo ""
}

case "${1:-all}" in
    all)
        echo "Running full cleanup..."
        ./cache.sh all
        ./cleanup.sh logs
        ./cleanup.sh temp
        echo "✓ Full cleanup completed"
        ;;
    cache)
        echo "Clearing caches..."
        ./cache.sh all
        ;;
    logs)
        echo "Clearing old logs..."
        find storage/logs -name "*.log" -mtime +7 -delete 2>/dev/null || true
        echo "✓ Old logs cleared"
        ;;
    temp)
        echo "Clearing temporary files..."
        find storage/framework -name "*.php" -mtime +1 -delete 2>/dev/null || true
        find storage/app -name "*.tmp" -delete 2>/dev/null || true
        echo "✓ Temporary files cleared"
        ;;
    help|--help|-h)
        show_help
        ;;
    *)
        echo "Unknown command: ${1}"
        show_help
        exit 1
        ;;
esac
