.PHONY: test test-coverage run-docs run-docs-ko docs-build docs-gen sync-v2-schema gen-v2-models gen-v2-inventory gen-v2-diff sync-v2-all

# --------------------------------
# Environment Variables
# --------------------------------

PYTHON_VERSION ?= 3.12
VENV_DIR ?= .venv

# --------------------------------
# Development Environment Commands
# --------------------------------

# Create virtual environment with uv using Python 3.12
uv-venv:
	uv venv $(VENV_DIR) --python $(PYTHON_VERSION)
	@echo "Virtual environment created at $(VENV_DIR) with Python $(PYTHON_VERSION)"
	@echo "Run 'source $(VENV_DIR)/bin/activate' to activate"

# Install dependencies with uv
uv-install:
	uv sync --all-extras

# Create venv and install dependencies
uv-setup: uv-venv uv-install
	@echo "Development environment setup complete"

# Remove virtual environment
uv-clean-venv:
	rm -rf $(VENV_DIR)
	@echo "Virtual environment removed"

# --------------------------------
# Testing Commands
# --------------------------------

# Run all tests
test:
	uv run python -m pytest tests/ -v

# Run tests with coverage report
test-coverage:
	uv run python -m pytest tests/ --cov=synapse_sdk --cov-report=term-missing --cov-report=html --cov-report=xml

# --------------------------------
# Documentation Commands
# --------------------------------

# Run Docusaurus Documentation Server for local development
run-docs:
	cd docs && \
		npx docusaurus start --host 0.0.0.0 --port 3500

# Run Docusaurus Documentation Server for Korean locale
run-docs-ko:
	cd docs && \
		npx docusaurus start --host 0.0.0.0 --port 3500 --locale ko

# Build docs
docs-build:
	cd docs && npm run build

# Generate API docs from Python docstrings
docs-gen:
	uv run pydoc-markdown

# --------------------------------
# Backend v2 Schema / Codegen
# --------------------------------

# Sync v2 OpenAPI schema cache (no codegen)
sync-v2-schema:
	uv run python scripts/sync_v2_schema.py

# Regenerate Pydantic models from cached schema (requires datamodel-code-generator)
gen-v2-models:
	uv run python scripts/sync_v2_schema.py --gen-models

# Regenerate INVENTORY.md from cached schema (includes v1↔v2 diff section)
gen-v2-inventory:
	uv run python scripts/sync_v2_schema.py --gen-inventory

# Print the v1↔v2 endpoint diff to stdout (no file changes — handy in CI / review)
gen-v2-diff:
	uv run python scripts/sync_v2_schema.py --gen-v1-diff

# Sync schema + regenerate models + inventory
sync-v2-all:
	uv run python scripts/sync_v2_schema.py --all

