# Trade-In MVP — удобные команды для локальной разработки.

.PHONY: help up down rebuild logs ps shell-backend shell-postgres test-estimate clean

help:
	@echo "Trade-In MVP — Makefile commands:"
	@echo ""
	@echo "  make up               — собрать и запустить весь стек (caddy + frontend + backend + postgres)"
	@echo "  make down             — остановить стек (volumes остаются)"
	@echo "  make rebuild          — пересобрать образы и перезапустить (нужно при изменении Dockerfile или deps)"
	@echo "  make logs             — tail -f всех контейнеров"
	@echo "  make logs-backend     — tail -f только backend"
	@echo "  make logs-frontend    — tail -f только frontend"
	@echo "  make ps               — статус контейнеров + healthcheck"
	@echo "  make shell-backend    — bash внутри backend контейнера"
	@echo "  make shell-postgres   — psql внутри postgres контейнера"
	@echo "  make test-estimate    — пример POST /api/v1/trade-in/estimate через curl"
	@echo "  make clean            — down + rm volumes (УДАЛИТ данные Postgres!)"
	@echo ""

up:
	docker compose up -d --build
	@echo ""
	@echo "✅ Стек запущен."
	@echo "   Frontend:        http://localhost:8080  (auto-redirect → /trade-in)"
	@echo "   Mockup preview:  http://localhost:8080/preview/tradein.html"
	@echo "   Backend health:  http://localhost:8080/health"
	@echo "   Backend OpenAPI: http://localhost:8000/docs"

down:
	docker compose down

rebuild:
	docker compose up -d --build --force-recreate

logs:
	docker compose logs -f --tail=100

logs-backend:
	docker compose logs -f --tail=100 backend

logs-frontend:
	docker compose logs -f --tail=100 frontend

ps:
	docker compose ps

shell-backend:
	docker compose exec backend bash

shell-postgres:
	docker compose exec postgres psql -U tradein -d tradein

test-estimate:
	@echo "POST /api/v1/trade-in/estimate..."
	@curl -sS -X POST http://localhost:8080/api/v1/trade-in/estimate \
		-H 'Content-Type: application/json' \
		-d '{"address":"ул. Малышева, 1, Екатеринбург","area_m2":54,"rooms":2,"floor":5,"total_floors":17,"year_built":1985,"house_type":"panel","repair_state":"good","has_balcony":true}' \
		| python3 -m json.tool

clean:
	docker compose down -v
	@echo "⚠️  Volumes удалены — Postgres данные стёрты."
