#!/bin/bash
# Overnight Development Commit Message Hook
# Ensures commits follow conventional commits format

COMMIT_MSG_FILE=$1
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")

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

if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
    echo "❌ Commit message doesn't follow conventional commits format"
    echo ""
    echo "📝 Format: <type>(<scope>): <description>"
    echo ""
    echo "Valid types:"
    echo "  feat:     New feature"
    echo "  fix:      Bug fix"
    echo "  docs:     Documentation changes"
    echo "  style:    Code style changes (formatting, etc.)"
    echo "  refactor: Code refactoring"
    echo "  test:     Adding or updating tests"
    echo "  chore:    Maintenance tasks"
    echo "  perf:     Performance improvements"
    echo ""
    echo "Examples:"
    echo "  feat(auth): add JWT authentication"
    echo "  fix(api): handle null response from database"
    echo "  test(auth): add integration tests for login"
    echo ""
    exit 1
fi

echo "✅ Commit message follows conventional commits"
