#!/bin/sh
# Auto-format staged JSON files in postman folder before commit

# Get list of staged JSON files in postman folder
STAGED_JSON=$(git diff --cached --name-only --diff-filter=ACM -- 'postman/**/*.json')

if [ -n "$STAGED_JSON" ]; then
    echo "Formatting staged Postman JSON files..."
    
    # Format each staged file
    echo "$STAGED_JSON" | while read -r file; do
        if [ -f "$file" ]; then
            npx --prefix postman prettier --write "$file"
            git add "$file"
        fi
    done
    
    echo "Done formatting."
fi
