#!/usr/bin/env bash

# deprecated

set -euo pipefail

echo "Generating mocks with mockery in parallel..."

# Use associative array to deduplicate package directories
declare -A seen_dirs=()

# Find all directories that contain Go files with interfaces
while IFS= read -r file; do
  dir=$(dirname "$file")
  seen_dirs["$dir"]=1
done < <(find ./pkg ./domain -type f -name '*.go' \
  ! -name '*_test.go' \
  ! -path './vendor/*' \
  ! -path '*/mocks/*')

# Process each package directory in parallel
for pkg_dir in "${!seen_dirs[@]}"; do
  (
    echo "🔧 Generating mocks in $pkg_dir"
    mkdir -p "$pkg_dir/mocks"
    ./bin/mockery --all --case=underscore --dir="$pkg_dir" --output="$pkg_dir/mocks" || echo "⚠️  No mockable interfaces in $pkg_dir"
  ) &
done

# Wait for all background jobs to complete
wait

echo "✅ All mocks generated in parallel."
