# VCradle Development Makefile

.PHONY: help install test test-unit test-integration test-coverage lint format type-check security-check clean build docker-build docker-run

# Default target
help:
	@echo "VCradle Development Commands"
	@echo "=================================="
	@echo "install          Install dependencies"
	@echo "test             Run all tests"
	@echo "test-unit        Run unit tests only"
	@echo "test-integration Run integration tests only"
	@echo "test-coverage    Run tests with coverage"
	@echo "lint             Run code linting"
	@echo "format           Format code"
	@echo "type-check       Run type checking"
	@echo "security-check   Run security checks"
	@echo "quality          Run all quality checks"
	@echo "clean            Clean up generated files"
	@echo "build            Build the application"
	@echo "docker-build     Build Docker image"
	@echo "docker-run       Run Docker containers"

# Installation
install:
	pip install -r requirements.txt
	pip install -r requirements-test.txt

install-dev:
	pip install -e .
	pip install -r requirements-test.txt

# Testing
test:
	pytest

test-unit:
	pytest -m unit

test-integration:
	pytest -m integration

test-api:
	pytest -m api

test-coverage:
	pytest --cov=app --cov-report=html --cov-report=term-missing

test-fast:
	pytest -m "not slow"

test-verbose:
	pytest -v -s

# Code Quality
lint:
	flake8 app/ tests/
	isort --check-only app/ tests/

format:
	black app/ tests/
	isort app/ tests/

type-check:
	mypy app/

security-check:
	bandit -r app/
	safety check

quality: lint type-check security-check

# Development
clean:
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete
	rm -rf .pytest_cache/
	rm -rf htmlcov/
	rm -rf .coverage
	rm -rf dist/
	rm -rf build/
	rm -rf *.egg-info/

build:
	python setup.py sdist bdist_wheel

# Docker
docker-build:
	cd .. && docker-compose build

docker-run:
	cd .. && docker-compose up -d

docker-stop:
	cd .. && docker-compose down

docker-logs:
	cd .. && docker-compose logs -f

# Development server
dev:
	python main_app.py

dev-reload:
	uvicorn main_app:app --reload --host 0.0.0.0 --port 8000

# Database operations (ORM-based)
db-init:
	python -c "from core.orm import init_database, create_all_tables; import asyncio; asyncio.run(init_database('data/vcradle.db')); asyncio.run(create_all_tables())"

db-migrate:
	@echo "Database migrations are handled automatically by SQLAlchemy ORM"

# Performance testing
perf-test:
	pytest -m slow --benchmark-only

load-test:
	locust -f tests/load_test.py --host=http://localhost:8000

# Documentation
docs:
	python -c "import webbrowser; webbrowser.open('http://localhost:8000/api/docs')"

# CI/CD preparation
ci-test:
	pytest --junitxml=test-results.xml --cov=app --cov-report=xml

# Environment setup
setup-env:
	cp .env.example .env
	echo "Please edit .env file with your configuration"

# Monitoring
monitor-logs:
	tail -f /vcradle/logs/*.log

monitor-metrics:
	curl -s http://localhost:8000/api/v1/metrics/system | jq

health-check:
	curl -s http://localhost:8000/health | jq