#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

# Conventional Commits validator
commit_msg_file=$1
commit_msg=$(cat "$commit_msg_file")

# Conventional Commits pattern
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\(.+\))?(!)?:\s.{1,}'

if ! echo "$commit_msg" | grep -qE "$pattern"; then
    echo "❌ Error: Commit message does not follow Conventional Commits format"
    echo ""
    echo "Expected format:"
    echo "  <type>[optional scope][!]: <description>"
    echo ""
    echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
    echo ""
    echo "Examples:"
    echo "  feat: add new feature"
    echo "  fix(api): resolve timeout issue"
    echo "  feat!: breaking change"
    echo ""
    exit 1
fi

exit 0
