.PHONY: all build run seed export-content test fmt fmt-check vet clean

BIN_DIR := bin
DB_PATH := anl.db

all: fmt-check vet build test

build:
	@mkdir -p $(BIN_DIR)
	@echo "Building api server..."
	go build -o $(BIN_DIR)/api ./cmd/api
	@echo "Building seeder..."
	go build -o $(BIN_DIR)/seed ./cmd/seed
	@echo "Building content exporter..."
	go build -o $(BIN_DIR)/export-content ./cmd/export-content

run: build
	./$(BIN_DIR)/api --db $(DB_PATH)

seed: build
	./$(BIN_DIR)/seed --db $(DB_PATH) --seed-dir seed/data

export-content: build
	@echo "⚠️ Notice: Frontend has migrated to real-time dynamic runtime fetching (force-dynamic)."
	@echo "export-content is deprecated to prevent re-introducing static content data files."
	./$(BIN_DIR)/export-content --db $(DB_PATH) --out-dir ../refer_landing_page/content

fmt:
	gofmt -w .

fmt-check:
	@test -z "$$(gofmt -l .)" || (echo "gofmt check failed on files:" && gofmt -l . && exit 1)

vet:
	go vet ./...

test: fmt-check vet
	go test -v ./...

backup-db:
	@mkdir -p db/backup
	sqlite3 $(DB_PATH) ".backup 'db/backup/anl.db'"
	sqlite3 $(DB_PATH) ".dump" > db/backup/anl_dump.sql
	@echo "✅ Database backed up to db/backup/anl.db and db/backup/anl_dump.sql"

clean:
	rm -rf $(BIN_DIR) *.db*
