.PHONY: install dev prod stop remove

install:
	sudo apt install -y poppler-utils libpango-1.0-0 libcairo2 libgdk-pixbuf-2.0-0 libffi-dev
	pip install --break-system-packages fastapi uvicorn[standard] aiosqlite weasyprint pdf2image
	cd frontend && npm install

dev:
	@echo "Backend: http://localhost:8000"
	@echo "Frontend: http://localhost:5173"
	@cd backend && uvicorn main:app --reload --port 8000 &
	@cd frontend && npx vite --port 5173

prod:
	@echo "Backend: http://localhost:8000"
	@cd frontend && npx vite build
	@cd backend && uvicorn main:app --host 0.0.0.0 --port 8000

stop:
	-@pkill -f "uvicorn main:app" 2>/dev/null
	-@pkill -f "vite --port 5173" 2>/dev/null
	@echo "Server gestoppt."

remove: stop
	@echo "Lösche Datenbank und generierte Dateien..."
	rm -f guides.db
	rm -rf storage/html/* storage/pdf/*
	@echo "Fertig."
