# MarkiTect Content Capability Makefile
# Content parsing and statistics for MarkdownMatters documents

# Capability metadata
CAPABILITY_NAME := markitect-content
CAPABILITY_DESCRIPTION := Content parsing and statistics for MarkdownMatters documents

# Default target
.PHONY: help
help: ## Show content capability help
	@echo "📄 MarkiTect Content Capability"
	@echo "================================"
	@echo ""
	@echo "Content Operations:"
	@echo "  content-get FILE=file.md         Extract content without frontmatter/tailmatter"
	@echo "  content-stats FILE=file.md       Calculate content statistics (word count, etc.)"
	@echo "  content-stats-json FILE=file.md  Get content statistics in JSON format"
	@echo ""
	@echo "Development & Setup:"
	@echo "  content-install                  Install content capability"
	@echo "  content-install-dev              Install with development dependencies"
	@echo "  content-test                     Run content capability tests"
	@echo "  content-test-cov                 Run tests with coverage report"
	@echo "  content-lint                     Run code quality checks"
	@echo "  content-clean                    Clean build artifacts"

# Check if markitect command is available (assumes CLI integration)
MARKITECT_CLI := $(shell command -v markitect 2> /dev/null)

# Content Operations
.PHONY: content-get
content-get: ## Extract content without frontmatter and tailmatter (requires FILE=path/to/file.md)
ifndef FILE
	@echo "❌ FILE is required. Usage: make content-get FILE=document.md"
	@exit 1
endif
ifndef MARKITECT_CLI
	@echo "⚠️  markitect CLI not available, trying direct Python execution..."
	cd capabilities/markitect-content && python -m markitect_content.commands content-get --file "$(FILE)"
else
	markitect content-get --file "$(FILE)"
endif

.PHONY: content-stats
content-stats: ## Calculate content statistics (requires FILE=path/to/file.md)
ifndef FILE
	@echo "❌ FILE is required. Usage: make content-stats FILE=document.md"
	@exit 1
endif
ifndef MARKITECT_CLI
	@echo "⚠️  markitect CLI not available, trying direct Python execution..."
	cd capabilities/markitect-content && python -m markitect_content.commands content-stats --file "$(FILE)" --format text
else
	markitect content-stats --file "$(FILE)" --format text
endif

.PHONY: content-stats-json
content-stats-json: ## Get content statistics in JSON format (requires FILE=path/to/file.md)
ifndef FILE
	@echo "❌ FILE is required. Usage: make content-stats-json FILE=document.md"
	@exit 1
endif
ifndef MARKITECT_CLI
	@echo "⚠️  markitect CLI not available, trying direct Python execution..."
	cd capabilities/markitect-content && python -m markitect_content.commands content-stats --file "$(FILE)" --format json
else
	markitect content-stats --file "$(FILE)" --format json
endif

# Development and Setup
.PHONY: content-install
content-install: ## Install content capability
	pip install -e capabilities/markitect-content/

.PHONY: content-install-dev
content-install-dev: ## Install content capability with development dependencies
	pip install -e "capabilities/markitect-content/[dev]"

.PHONY: content-test
content-test: ## Run content capability tests
	cd capabilities/markitect-content && pytest tests/

.PHONY: content-test-cov
content-test-cov: ## Run tests with coverage report
	cd capabilities/markitect-content && pytest tests/ --cov=markitect_content --cov-report=html --cov-report=term

.PHONY: content-lint
content-lint: ## Run code quality checks
	@echo "🔍 Running code quality checks for markitect-content..."
	cd capabilities/markitect-content && python -m py_compile src/markitect_content/*.py
	@echo "✅ Code quality checks passed"

.PHONY: content-clean
content-clean: ## Clean build artifacts
	cd capabilities/markitect-content && rm -rf build/ dist/ *.egg-info/ __pycache__/ .pytest_cache/ htmlcov/ .coverage
	find capabilities/markitect-content -name "*.pyc" -delete
	find capabilities/markitect-content -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true

# Library Functions (for other capabilities to use)
.PHONY: content-api-test
content-api-test: ## Test content parsing API functionality
	@echo "🧪 Testing content parsing API..."
	cd capabilities/markitect-content && python -c "from src.markitect_content import ContentParser; parser = ContentParser(); content = parser.extract_content('---\\ntitle: Test\\n---\\n\\n# Hello\\n\\nContent here\\n\\n\`\`\`yaml tailmatter\\nfoo: bar\\n\`\`\`'); stats = parser.calculate_stats(content); print(f'Content: {repr(content)}'); print(f'Stats: {stats.to_dict()}')"

# Meta information for capability discovery
.PHONY: capability-info
capability-info: ## Show capability information
	@echo "Name: $(CAPABILITY_NAME)"
	@echo "Description: $(CAPABILITY_DESCRIPTION)"
	@echo "Type: Library capability with CLI commands"
	@echo "Main functions: Content extraction, statistics calculation"
	@echo "CLI commands: content-get, content-stats"
	@echo "Targets:"
	@$(MAKE) --no-print-directory help | grep "^  " | sed 's/^  /    /'