SHELL := /bin/zsh
COMPOSE := docker compose

.PHONY: help up down restart logs ps build pull clean api-shell db-shell migrate lint

help:
	@echo "RoleForge commands:"
	@echo "  make up          - start all services in background"
	@echo "  make down        - stop services"
	@echo "  make restart     - restart services"
	@echo "  make logs        - follow compose logs"
	@echo "  make ps          - show service status"
	@echo "  make build       - rebuild images"
	@echo "  make pull        - pull base images"
	@echo "  make clean       - stop and remove volumes"
	@echo "  make api-shell   - shell inside api container"
	@echo "  make db-shell    - psql shell in postgres container"
	@echo "  make migrate     - re-run init sql inside postgres"
	@echo "  make lint        - run ruff inside api container"

up:
	$(COMPOSE) up -d --build

down:
	$(COMPOSE) down

restart:
	$(COMPOSE) down && $(COMPOSE) up -d --build

logs:
	$(COMPOSE) logs -f --tail=200

ps:
	$(COMPOSE) ps

build:
	$(COMPOSE) build

pull:
	$(COMPOSE) pull

clean:
	$(COMPOSE) down -v --remove-orphans

api-shell:
	$(COMPOSE) exec api /bin/bash

db-shell:
	$(COMPOSE) exec postgres psql -U roleforge -d roleforge

migrate:
	$(COMPOSE) exec -T postgres psql -U roleforge -d roleforge < app/sql/001_init.sql

lint:
	$(COMPOSE) run --rm api ruff check app
