SHELL := /bin/bash
COMPOSE := docker compose
PHP := $(COMPOSE) exec app php
COMPOSER := $(COMPOSE) run --rm app composer

.PHONY: help up down build install composer update subscribe unsubscribe selftest logs ps test clean

help:
	@echo "Bot commands:"
	@echo "  make build          — build docker images"
	@echo "  make up             — start nginx + php-fpm"
	@echo "  make down           — stop containers"
	@echo "  make install        — composer install (first time)"
	@echo "  make update         — composer update"
	@echo "  make subscribe      — register webhook with MAX (uses WEBHOOK_URL)"
	@echo "  make unsubscribe    — remove webhook"
	@echo "  make selftest       — run smoke tests across all endpoint groups"
	@echo "  make bot-info       — print BotInfo JSON"
	@echo "  make logs           — tail app + nginx logs"
	@echo "  make test           — run PHPUnit"

build:
	$(COMPOSE) build

up:
	$(COMPOSE) up -d

down:
	$(COMPOSE) down

install:
	$(COMPOSE) run --rm app composer install

composer:
	$(COMPOSER) $(CMD)

update:
	$(COMPOSE) run --rm app composer update

subscribe:
	$(PHP) bin/console webhook:subscribe

unsubscribe:
	$(PHP) bin/console webhook:unsubscribe

selftest:
	$(PHP) bin/console selftest

bot-info:
	$(PHP) bin/console bot:info

ps:
	$(COMPOSE) ps

logs:
	$(COMPOSE) logs -f app nginx

test:
	$(COMPOSE) run --rm app vendor/bin/phpunit

clean:
	$(COMPOSE) down -v
	rm -rf vendor
