#!/bin/bash

echo "=== SMART DUPLICATE FINDER ==="
echo "Checking YellowMellow vs Photography overlaps..."

# Function to compare directories efficiently
compare_dirs() {
    local source_dir="$1"
    local target_dir="$2"
    local comparison_name="$3"
    
    echo "--- $comparison_name ---"
    
    # Use rsync dry-run to find what would be copied (i.e., what's different)
    rsync -av --dry-run --existing "$source_dir/" "$target_dir/" 2>/dev/null | \
        grep -E "^\." | head -10
    
    echo ""
}

# Check YellowMellow content against Photography folders
echo "1. Checking YellowMellow Summer Set vs Photography..."
if [ -d "YellowMellow/2025 Summer Set" ] && [ -d "Photography/Photography (2024)/Edits/YellowMellow Summer Set" ]; then
    compare_dirs "YellowMellow/2025 Summer Set" "Photography/Photography (2024)/Edits/YellowMellow Summer Set" "Summer Set Comparison"
fi

echo "2. Checking YellowMellow Poster vs Photography..."
if [ -d "YellowMellow/Yellow Mellow Poster Queen" ] && [ -d "Photography/Photography (2024)/Edits/YellowMellow Poster" ]; then
    compare_dirs "YellowMellow/Yellow Mellow Poster Queen" "Photography/Photography (2024)/Edits/YellowMellow Poster" "Poster Comparison"
fi

# Find YellowMellow content in Photography by filename matching
echo "3. Finding YellowMellow files in Photography by name..."
find Photography -type f -name "*yellow*" -o -name "*mellow*" | while read file; do
    basename_file=$(basename "$file")
    # Check if same filename exists in YellowMellow
    if find YellowMellow -name "$basename_file" -type f | grep -q .; then
        echo "POTENTIAL DUPLICATE: $file"
        echo "  Also exists in: $(find YellowMellow -name "$basename_file" -type f)"
        echo ""
    fi
done

echo "=== SUMMARY ==="
echo "YellowMellow directories: $(find YellowMellow -type d | wc -l)"
echo "Photography YellowMellow references: $(find Photography -iname "*yellow*" -o -iname "*mellow*" | wc -l)"