VERSION := `awk '/^__version__ = .*/ {gsub(/__version__ = |"/, ""); print}' ./pgai/__init__.py`

# Show list of recipes
default:
    @just --list

# Display the current pgai version
show-version:
	@echo "pgai version is: {{VERSION}}"

# Remove build artifacts and temporary files
clean:
	@rm -rf ./build
	@rm -rf ./pgai.egg-info
	@rm -rf ./dist
	@rm -rf ./.ruff_cache
	@rm -rf ./.pytest_cache
	@rm -rf ./.mypy_cache
	@find . -type d -name "__pycache__" -exec rm -rf {} +

# Build source distribution and wheel package
build:
	@uv build
	@uv run --no-project twine check ./dist/*

# Install the wheel package locally
install:
	@uv sync --all-extras

# Remove the installed pgai package
uninstall:
	@uv pip uninstall -y pgai

# Run pytest test suite
test:
	@uv run --no-project pytest

# Run ruff linter checks
lint:
	@uv run --no-project ruff check ./

# Run ruff linter checks and fix all auto-fixable issues
lint-fix:
	@uv run --no-project ruff check ./ --fix

# Run pyright type checking
type-check:
	@uv run --no-project pyright ./

# Runs ruff to check formatting of the python source files
format:
	@uv run --no-project ruff format --diff ./

# Runs ruff to check formatting of the python source files and fix all auto-fixable issues
format-fix:
	@uv run --no-project ruff format ./

# Run both linter and type-checking checks and fix all auto-fixable issues
fix: lint-fix format-fix

# CI pipeline. Runs all recipes needed for ensuring the code is ready to be integrated. Triggered by GH Actions
ci: install lint type-check format test build

# Build Docker image with version tag
docker-build:
	@docker build -t pgai-cli:latest -t "pgai-cli:{{VERSION}}" .

# Run the Docker container in detached mode
docker-run:
	@docker run -d --name pgai-cli "pgai-cli:{{VERSION}}"

# Stop the running Docker container
docker-stop:
	@docker stop pgai-cli

# Remove the Docker container and its volumes
docker-rm:
	@docker rm --force --volumes pgai-cli
