.PHONY: help dev-up dev-down dev-build dev-logs prod-up prod-down prod-build prod-logs shell migrate createsuperuser clean

help:
	@echo "Доступные команды:"
	@echo "  make dev-up          - Запустить development окружение"
	@echo "  make dev-down        - Остановить development окружение"
	@echo "  make dev-build       - Пересобрать development контейнеры"
	@echo "  make dev-logs        - Показать логи development"
	@echo "  make prod-up         - Запустить production окружение"
	@echo "  make prod-down       - Остановить production окружение"
	@echo "  make prod-build      - Пересобрать production контейнеры"
	@echo "  make prod-logs       - Показать логи production"
	@echo "  make shell           - Открыть Django shell"
	@echo "  make migrate         - Выполнить миграции"
	@echo "  make createsuperuser - Создать суперпользователя"
	@echo "  make clean           - Удалить все контейнеры и volumes"

# Development команды
dev-up:
	docker-compose up -d

dev-down:
	docker-compose down

dev-build:
	docker-compose up -d --build

dev-logs:
	docker-compose logs -f

dev-restart:
	docker-compose restart web

# Production команды
prod-up:
	docker-compose -f docker-compose.prod.yaml up -d

prod-down:
	docker-compose -f docker-compose.prod.yaml down

prod-build:
	docker-compose -f docker-compose.prod.yaml up -d --build

prod-logs:
	docker-compose -f docker-compose.prod.yaml logs -f

prod-restart:
	docker-compose -f docker-compose.prod.yaml restart web

# Django команды (для development по умолчанию)
shell:
	docker-compose exec web python manage.py shell

migrate:
	docker-compose exec web python manage.py migrate

makemigrations:
	docker-compose exec web python manage.py makemigrations

createsuperuser:
	docker-compose exec web python manage.py createsuperuser

collectstatic:
	docker-compose exec web python manage.py collectstatic --noinput

# Для production
prod-shell:
	docker-compose -f docker-compose.prod.yaml exec web python manage.py shell

prod-migrate:
	docker-compose -f docker-compose.prod.yaml exec web python manage.py migrate

prod-createsuperuser:
	docker-compose -f docker-compose.prod.yaml exec web python manage.py createsuperuser

# Backup и восстановление
backup:
	docker-compose exec db pg_dump -U geralt geodb > backup_$(shell date +%Y%m%d_%H%M%S).sql

restore:
	@read -p "Введите имя файла backup: " file; \
	docker-compose exec -T db psql -U geralt geodb < $$file

# Очистка
clean:
	docker-compose down -v
	docker system prune -f

clean-all:
	docker-compose down -v
	docker-compose -f docker-compose.prod.yaml down -v
	docker system prune -af --volumes

# Проверка статуса
status:
	docker-compose ps

prod-status:
	docker-compose -f docker-compose.prod.yaml ps
