.PHONY: help install dev test clean docker-build docker-run docker-compose-up docker-compose-down lint format

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 dependencies
	pip install -r requirements.txt

dev: ## Run development server
	python run.py

test: ## Run tests
	pytest

test-cov: ## Run tests with coverage
	pytest --cov=app --cov-report=html --cov-report=term-missing

clean: ## Clean up cache files
	find . -type f -name "*.pyc" -delete
	find . -type d -name "__pycache__" -delete
	rm -rf .pytest_cache
	rm -rf htmlcov
	rm -rf .coverage

docker-build: ## Build Docker image
	docker build -t flask-sidebar-app .

docker-run: ## Run Docker container
	docker run -p 8000:8000 flask-sidebar-app

docker-compose-up: ## Start all services with Docker Compose
	docker-compose up --build

docker-compose-down: ## Stop all services
	docker-compose down

docker-compose-logs: ## View logs from all services
	docker-compose logs -f

init-db: ## Initialize database
	flask db init
	flask db migrate -m "Initial migration"
	flask db upgrade

migrate: ## Create new migration
	flask db migrate

upgrade-db: ## Apply migrations
	flask db upgrade

lint: ## Run linting
	flake8 app tests

format: ## Format code
	black app tests

setup: ## Initial project setup
	cp .env.example .env
	python -m venv .venv
	@echo "Now run: source .venv/bin/activate && make install"

production-check: ## Check production readiness
	@echo "Checking production configuration..."
	@python -c "from app.config import Config; c = Config(); print('✓ SECRET_KEY configured' if c.SECRET_KEY != 'dev' else '✗ Change SECRET_KEY')"
	@python -c "from app.config import Config; c = Config(); print('✓ Database configured' if not c.SQLALCHEMY_DATABASE_URI.startswith('sqlite') else '⚠ Using SQLite (consider PostgreSQL for production)')"
	@python -c "import os; print('✓ Environment file exists' if os.path.exists('.env') else '✗ Create .env file')"
