echo "🔍 Running pre-commit quality checks..."

# Run lint-staged first (includes linting and formatting)
echo "🎨 Running lint-staged..."
pnpm run lint-staged
if [ $? -ne 0 ]; then
    echo "❌ Linting or formatting failed. Please fix the issues and try again."
    exit 1
fi

# Type check to catch TS errors before committing
echo "🔎 Running TypeScript type-check..."
pnpm run type-check
if [ $? -ne 0 ]; then
    echo "❌ TypeScript type-check failed. Please fix type errors before committing."
    exit 1
fi

# Structure quality checks
echo ""
echo "🏗️  Running structure quality checks..."

# 1. Naming convention check
echo "   🔤 Checking naming conventions..."
node scripts/check-naming-convention.js
if [ $? -ne 0 ]; then
    echo "❌ Naming convention check failed. Please fix the naming issues."
    exit 1
fi

# 2. File size check
echo "   📏 Checking file sizes..."
node scripts/check-file-size.js
if [ $? -ne 0 ]; then
    echo "❌ File size check failed. Please refactor large files."
    exit 1
fi

# 3. Placeholder check
echo "   📝 Checking for placeholder files..."
node scripts/check-placeholder.js
if [ $? -ne 0 ]; then
    echo "❌ Placeholder check failed. Please implement or remove placeholder files."
    exit 1
fi

# 4. Empty folder check
echo "   📁 Checking for empty folders..."
node scripts/check-empty-folders.js
if [ $? -ne 0 ]; then
    echo "❌ Empty folder check failed. Please remove or add files to empty folders."
    exit 1
fi

# Security check (temporarily disabled - 12 vulnerabilities remain, reduced from 42)
# echo "🔒 Running security audit..."
# pnpm run security:audit
# if [ $? -ne 0 ]; then
#     echo "❌ Security vulnerabilities found. Please fix them before committing."
#     exit 1
# fi

echo ""
echo "✅ All pre-commit checks passed!"
