#!/bin/bash
set -euo pipefail

# Install only ruff and mypy if not available (without full dev dependencies)
if ! command -v ruff &> /dev/null; then
    echo "Installing ruff..." >&2
    pip install --no-cache-dir -q ruff
fi

if ! command -v mypy &> /dev/null; then
    echo "Installing mypy..." >&2
    pip install --no-cache-dir -q mypy types-PyYAML
fi

echo "Running ruff check..." >&2
ruff check src/ tests/ >&2
RUFF_EXIT=$?

echo "Running mypy..." >&2
mypy src/ >&2
MYPY_EXIT=$?

if [ $RUFF_EXIT -ne 0 ] || [ $MYPY_EXIT -ne 0 ]; then
    echo "Checks failed." >&2
    echo 1
    exit 1
fi

echo "All checks passed." >&2
echo 0
exit 0
