#!/bin/bash
# Custom yamllint wrapper that only lints Claude-generated YAML files
# Only processes files with the Claude header comment

CLAUDE_HEADER="# Generated by Claude - Home Assistant Configuration, https://github.com/philippb/claude-homeassistant"
YAMLLINT_CONFIG="public/.yamllint.yml"
EXIT_CODE=0

# Filter files to only include Claude-generated ones
CLAUDE_FILES=()

for file in "$@"; do
    # Check if it's a YAML file
    if [[ "$file" =~ \.(yaml|yml)$ ]]; then
        # Check if file exists and has Claude header
        if [[ -f "$file" ]] && head -3 "$file" 2>/dev/null | grep -Fq "$CLAUDE_HEADER"; then
            CLAUDE_FILES+=("$file")
            echo "Will lint Claude-generated file: $file"
        else
            echo "Skipping non-Claude file: $file"
        fi
    fi
done

# Run yamllint only on Claude-generated files
if [ ${#CLAUDE_FILES[@]} -gt 0 ]; then
    echo "Running yamllint on ${#CLAUDE_FILES[@]} Claude-generated YAML files..."
    source venv/bin/activate 2>/dev/null || true
    yamllint -c "$YAMLLINT_CONFIG" "${CLAUDE_FILES[@]}"
    EXIT_CODE=$?
else
    echo "No Claude-generated YAML files to lint."
fi

exit $EXIT_CODE
