BINARY := ems
CONFIG := configs/ems-config.yaml

.PHONY: build test dry-run run install lint

build:
	go build -o $(BINARY) .

test:
	go test ./...

dry-run: build
	./$(BINARY) -config $(CONFIG) -dry-run

run: build
	./$(BINARY) -config $(CONFIG)

install: build
	install -Dm755 $(BINARY) /usr/local/bin/$(BINARY)
	install -Dm644 systemd/ems.service /etc/systemd/system/ems.service
	systemctl daemon-reload
	@if [ ! -f /etc/ems/ems-config.yaml ]; then \
		install -Dm644 $(CONFIG) /etc/ems/ems-config.yaml; \
		echo "Config installed to /etc/ems/ems-config.yaml (first time)"; \
	else \
		echo "Config already exists at /etc/ems/ems-config.yaml — not overwritten"; \
	fi
	@echo "Run: systemctl enable --now ems"

lint:
	go vet ./...
