SHELL := /bin/bash
.PHONY: build build-web build-server build-tui run run-tui dev docker-up docker-down clean

GIT_SHA := $(shell git rev-parse --short HEAD)

# Build everything
build: build-web build-server

# Build the Go server
build-server:
	CGO_ENABLED=0 go build -o dumpster-server ./cmd/server

# Build the TUI client
build-tui:
	CGO_ENABLED=0 go build -o dumpster-tui ./cmd/tui

# Build the Tauri desktop app (Linux AppImage)
build-tauri:
	cd web && NODE_ENV=development NO_STRIP=true npx tauri build --bundles appimage

# Generate Swagger docs
docs:
	~/go/bin/swag init -g cmd/server/main.go -o docs

# Build the web frontend
build-web:
	cd web && ([ -s ~/.nvm/nvm.sh ] && . ~/.nvm/nvm.sh && GIT_SHA=$(GIT_SHA) npm run build || GIT_SHA=$(GIT_SHA) npm run build)

# Run the server locally (dev mode)
run: build-server
	./dumpster-server

# Run the TUI client
run-tui: build-tui
	./dumpster-tui

# Run web dev server (in a separate terminal)
dev-web:
	cd web && [ -s ~/.nvm/nvm.sh ] && . ~/.nvm/nvm.sh && npm run dev || (cd web && npm run dev)

# Start all backing services (no app, run that locally)
docker-dev:
	docker compose -f docker/compose.yml up postgres valkey minio livekit coturn -d

# Start everything in Docker
docker-up:
	docker compose -f docker/compose.yml up -d --build

# Stop everything
docker-down:
	docker compose -f docker/compose.yml down

# Stop and remove volumes
docker-clean:
	docker compose -f docker/compose.yml down -v

# Clean build artifacts
clean:
	rm -f dumpster-server dumpster-tui
	rm -rf web/dist
	rm -rf web/node_modules
