.PHONY: help install dev-backend dev-frontend dev-worker test lint clean

help: ## Show this help message
	@echo 'Usage: make [target]'
	@echo ''
	@echo 'Targets:'
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "  %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)

install: ## Install all dependencies
	@echo "Installing backend dependencies..."
	cd backend && poetry install
	@echo "Installing frontend dependencies..."
	cd frontend && npm install

dev-backend: ## Start backend development server
	cd backend && poetry run uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

dev-frontend: ## Start frontend development server
	cd frontend && npm run dev

dev-worker: ## Start Celery worker
	cd backend && poetry run celery -A app.tasks worker --loglevel=info


test-backend: ## Run backend tests
	cd backend && poetry run pytest

test-frontend: ## Run frontend tests
	cd frontend && npm run test

lint-backend: ## Lint backend code
	cd backend && poetry run ruff check . && poetry run mypy .

lint-frontend: ## Lint frontend code
	cd frontend && npm run lint && npm run type-check

lint: lint-backend lint-frontend ## Lint all code

clean: ## Clean build artifacts
	cd backend && rm -rf __pycache__ .pytest_cache .mypy_cache
	cd frontend && rm -rf node_modules/.cache dist

build-backend: ## Build backend Docker image
	cd backend && docker build -t accessible-video-backend .

build-frontend: ## Build frontend for production
	cd frontend && npm run build

# Development helpers
setup-env: ## Copy environment templates
	cp backend/.env.example backend/.env
	cp frontend/.env.example frontend/.env
	@echo "Environment files created. Please update with your actual values."

dev: ## Start all development services (requires tmux)
	tmux new-session -d -s accessible-video
	tmux send-keys -t accessible-video 'make dev-backend' C-m
	tmux split-window -t accessible-video
	tmux send-keys -t accessible-video 'make dev-frontend' C-m
	tmux split-window -t accessible-video
	tmux send-keys -t accessible-video 'make dev-worker' C-m
	tmux select-layout -t accessible-video tiled
	tmux attach -t accessible-video