.PHONY: build check test clean run-api run-importer setup-db migrate verify help frontend-dev frontend-build frontend-install

# Default target
help:
	@echo "0xArchive - Hyperliquid Historical Data API"
	@echo ""
	@echo "Setup commands:"
	@echo "  make setup-db      Create the database"
	@echo "  make migrate       Run all database migrations"
	@echo "  make verify        Verify setup is complete"
	@echo ""
	@echo "Build commands:"
	@echo "  make build         Build all backend crates (release)"
	@echo "  make check         Check all crates compile"
	@echo "  make clean         Clean build artifacts"
	@echo ""
	@echo "Run commands:"
	@echo "  make run-api       Start the REST API server"
	@echo "  make run-ws        Start the WebSocket server"
	@echo ""
	@echo "Frontend commands:"
	@echo "  make frontend-install  Install frontend dependencies"
	@echo "  make frontend-dev      Start frontend dev server"
	@echo "  make frontend-build    Build frontend for production"
	@echo ""
	@echo "Import commands:"
	@echo "  make import-help   Show importer help"
	@echo "  make import-status Show import progress"
	@echo ""
	@echo "Example imports:"
	@echo "  cargo run -p importer -- orderbook --start-date 2024-01-01 --end-date 2024-01-02 --coins BTC,ETH"
	@echo "  cargo run -p importer -- fills --start-date 2025-03-22 --end-date 2025-03-23"

# Build
build:
	cargo build --release

check:
	cargo check

clean:
	cargo clean
	rm -rf frontend/dist frontend/node_modules

# Database
setup-db:
	./scripts/setup_db.sh

migrate:
	./scripts/run_migrations.sh

verify:
	./scripts/verify_setup.sh

# Run services
run-api:
	cargo run --release -p api

run-ws:
	cargo run --release -p websocket

# Frontend
frontend-install:
	cd frontend && npm install

frontend-dev:
	cd frontend && npm run dev

frontend-build:
	cd frontend && npm run build

# Importer
import-help:
	cargo run -p importer -- --help

import-status:
	@echo "Checking import status..."
	cargo run -p importer -- status --data-type orderbook
	cargo run -p importer -- status --data-type fills
	cargo run -p importer -- status --data-type asset_ctxs

# Development: run API and frontend together
dev:
	@echo "Starting API server in background..."
	cargo run --release -p api &
	@echo "Starting frontend dev server..."
	cd frontend && npm run dev
