.PHONY: install-uv
install-uv:
ifeq ($(OS),Windows_NT)
	powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
else
	@if ! command -v uv &> /dev/null; then \
		curl -LsSf https://astral.sh/uv/install.sh | sh; \
	fi
endif

# Install dependencies for the project
.PHONY: install
install:
	@echo "Installing dependencies..."
	uv venv
	. .venv/bin/activate
	uv pip install -e ".[dev]"

.PHONY: build
build: clean build-purple-view
	@echo "Building dependencies..."
	uv build

.PHONY: build-purple-view
build-purple-view:
	make -C ../purple-view build
	cp -r ../purple-view/build/ src/lightly_purple/dist-purple-view-app

.PHONY: start
start: install build
	$(MAKE) start-example

.PHONY: start-example
start-example:
	@echo "Starting server..."
	PYTHONPATH=$(PWD) uv run src/lightly_purple/example.py

.PHONY: test
test: install build
	@echo "Running tests..."
	PYTHONPATH=$(PWD) uv run pytest

.PHONY: test-ci
test-ci:
	@echo "Running tests..."
	uv run pytest

.PHONY: publish
publish: build
	@echo "Publishing package..."
	uv publish

.PHONY: lint
lint:
	@echo "Linting project with ruff..."
	uv run ruff check

.PHONY: format
format:
	@echo "Formatting project with ruff..."
	uv run ruff format

.PHONY: lint-fix
lint-fix:
	uv run ruff check --fix

.PHONY: clean
clean:
	rm -rf *.db
	rm -rf *.db.wal
	rm -rf dist/*
	rm -rf src/lightly_purple/dist-purple-view-app
	find . -name "__pycache__" -type d -exec rm -rf {} +
	find . -name "*.egg-info" -type d -exec rm -rf {} +
