.PHONY: help lint test molecule-test molecule-converge molecule-destroy install build clean galaxy-install galaxy-build

# Default target
help:
	@echo "Available targets:"
	@echo "  help             - Show this help message"
	@echo "  lint             - Run ansible-lint on the collection"
	@echo "  test             - Run all tests (lint + molecule)"
	@echo "  molecule-test    - Run molecule test suite"
	@echo "  molecule-converge - Run molecule converge (without destroy)"
	@echo "  molecule-destroy - Destroy molecule test instances"
	@echo "  install          - Install collection dependencies"
	@echo "  build            - Build the collection tarball"
	@echo "  clean            - Clean build artifacts"
	@echo "  galaxy-install   - Install the collection from Ansible Galaxy"
	@echo "  galaxy-build     - Build and install collection locally"
	@echo "  galaxy-publish   - Build and publish collection to Ansible Galaxy"

# Linting
lint:
	ansible-lint .

# Testing
test: lint molecule-test

# Molecule testing
molecule-test:
	cd extensions && molecule test

molecule-converge:
	cd extensions && molecule converge

molecule-destroy:
	cd extensions && molecule destroy

# Installation and dependencies
install:
	ansible-galaxy install -r requirements.yml --force

# Build collection
build:
	rm -f danielfm-workstation-*.tar.gz
	ansible-galaxy collection build --force

# Clean build artifacts
clean:
	rm -f danielfm-workstation-*.tar.gz
	rm -rf .ansible

# Galaxy operations
galaxy-install:
	ansible-galaxy collection install danielfm.workstation --force

galaxy-build: build
	ansible-galaxy collection install danielfm-workstation-*.tar.gz --force

galaxy-publish: build
	ansible-galaxy collection publish danielfm-workstation-*.tar.gz

# Run the main playbook locally
run-local:
	ansible-playbook -i localhost, -c local playbooks/default.yml

# Run specific role
run-role:
	@if [ -z "$(ROLE)" ]; then \
		echo "Usage: make run-role ROLE=<role_name>"; \
		echo "Available roles: audio, backup, base, dev, main, security"; \
		exit 1; \
	fi
	ansible-playbook -i localhost, -c local -e "target=localhost" \
		-e "ansible_python_interpreter=/usr/bin/python3" \
		-m danielfm.workstation.$(ROLE) /dev/stdin <<< "---\n- hosts: localhost\n  roles:\n    - danielfm.workstation.$(ROLE)"

# Development helpers
dev-setup:
	python3 -m venv .venv
	.venv/bin/pip install ansible ansible-lint molecule molecule-plugins[podman]

dev-activate:
	@echo "Run: source .venv/bin/activate"
