#!/bin/sh
#
# Commit-msg hook: Validate conventional commit format
# Uses cargo-commitlint for validation
#

COMMIT_MSG_FILE="$1"

echo "📝 Validating commit message..."

# Check if cargo-commitlint is available
if command -v cargo >/dev/null 2>&1 && cargo commitlint --version >/dev/null 2>&1; then
    cat "$COMMIT_MSG_FILE" | cargo commitlint check
    EXIT_CODE=$?

    if [ $EXIT_CODE -ne 0 ]; then
        echo ""
        echo "❌ Commit message validation failed!"
        echo ""
        echo "Expected format: <type>(<scope>): <description>"
        echo ""
        echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
        echo "Scopes: core, platform, gpu, metal, dx12, render, assets, scene, audio,"
        echo "        physics, puppet, script, editor, macros, app, examples, deps, *"
        echo ""
        echo "Examples:"
        echo "  feat(render): add shadow mapping"
        echo "  fix(gpu): prevent buffer overflow"
        echo "  docs: update README"
        echo ""
        exit $EXIT_CODE
    fi

    echo "✅ Commit message OK"
else
    echo "⚠️  cargo-commitlint not installed, skipping validation"
    echo "   Install with: cargo install cargo-commitlint"
fi

