.PHONY: build up down restart logs logs-backend logs-frontend logs-db shell-backend shell-db clean pull deploy rebuild

# Build containers
build:
	docker-compose build

# Start containers
up:
	docker-compose up -d

# Stop containers
down:
	docker-compose down

# Restart all containers
restart:
	docker-compose restart

# Restart specific service
restart-backend:
	docker-compose restart backend

restart-frontend:
	docker-compose restart frontend

# View logs
logs:
	docker-compose logs -f

logs-backend:
	docker-compose logs -f backend

logs-frontend:
	docker-compose logs -f frontend

logs-db:
	docker-compose logs -f db

# Shell access
shell-backend:
	docker-compose exec backend bash

shell-db:
	docker-compose exec db psql -U animequiz -d animequiz

# Clean up
clean:
	docker-compose down -v --rmi local

# Pull latest code and rebuild
pull:
	git pull origin main

# Full deploy: pull, build, restart
deploy:
	git pull origin main
	docker-compose down
	docker-compose build
	docker-compose up -d --force-recreate

# Rebuild without cache
rebuild:
	docker-compose down
	docker-compose build --no-cache
	docker-compose up -d --force-recreate

# Show status
status:
	docker-compose ps

# Database backup
backup-db:
	docker-compose exec db pg_dump -U animequiz animequiz > backup_$$(date +%Y%m%d_%H%M%S).sql

# Database restore (usage: make restore-db FILE=backup.sql)
restore-db:
	cat $(FILE) | docker-compose exec -T db psql -U animequiz -d animequiz
