COMPOSE  := docker compose -f deploy/docker-compose.yml
DEV_DB   := postgres://tracker:tracker@localhost:5432/tracker?sslmode=disable

.PHONY: web web-dev build test test-integration run up down docker migrate install-agent

# Builds the Vue app into internal/web/dist/app, which the binary embeds.
web:
	cd web && { [ -d node_modules ] || npm ci; } && npm run build

# Vite dev server with hot reload; it proxies /api to `make run` on :8080.
web-dev:
	cd web && npm run dev

build: web
	go build -o bin/ ./cmd/...

test:
	go test ./...

# Runs the API tests against the compose Postgres (make up first).
test-integration:
	TEST_DATABASE_URL='$(DEV_DB)' go test -count=1 ./...

run: web
	AUTH_MODE=dev DEV_MODE=true DATABASE_URL='$(DEV_DB)' go run ./cmd/tracker serve

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

down:
	$(COMPOSE) down

docker:
	docker build -f deploy/Dockerfile -t activity-tracker .

migrate:
	DATABASE_URL='$(DEV_DB)' go run ./cmd/tracker migrate

install-agent:
	go build -o $(HOME)/.local/bin/hypr-agent ./cmd/hypr-agent
	install -Dm644 deploy/systemd/hypr-agent.service $(HOME)/.config/systemd/user/hypr-agent.service
	systemctl --user daemon-reload
