# Makefile for configuration tasks

.PHONY: config config-advanced config-backup config-restore config-validate

# Run basic configuration
config:
	@echo "Running basic configuration..."
	./scripts/configure-network.sh

# Run advanced configuration
config-advanced:
	@echo "Running advanced configuration..."
	./scripts/configure-network-advanced.sh

# Backup configuration
config-backup:
	@echo "Backing up configuration..."
	mkdir -p .config-backup
	cp -r config .config-backup/
	cp -r terraform/terraform.tfvars .config-backup/ 2>/dev/null || true
	cp -r helm/besu-network/values.yaml .config-backup/ 2>/dev/null || true
	@echo "Configuration backed up to .config-backup/"

# Restore configuration
config-restore:
	@echo "Restoring configuration from backup..."
	if [ -d .config-backup ]; then \
		cp -r .config-backup/* .; \
		echo "Configuration restored from .config-backup/"; \
	else \
		echo "No backup found"; \
	fi

# Validate configuration
config-validate:
	@echo "Validating configuration..."
	@python3 -c "import json; json.load(open('config/genesis.json'))" && echo "✓ genesis.json is valid JSON"
	@test -f config/validators/besu-config.toml && echo "✓ validators/besu-config.toml exists"
	@test -f config/sentries/besu-config.toml && echo "✓ sentries/besu-config.toml exists"
	@test -f config/rpc/besu-config.toml && echo "✓ rpc/besu-config.toml exists"
	@test -f terraform/terraform.tfvars && echo "✓ terraform.tfvars exists"
	@test -f helm/besu-network/values.yaml && echo "✓ values.yaml exists"
	@echo "Configuration validation complete"

# Show configuration summary
config-summary:
	@if [ -f CONFIG_SUMMARY.md ]; then \
		cat CONFIG_SUMMARY.md; \
	else \
		echo "No configuration summary found. Run 'make config' first."; \
	fi

# Help
config-help:
	@echo "Configuration Makefile Commands:"
	@echo "  make config           - Run basic configuration"
	@echo "  make config-advanced  - Run advanced configuration"
	@echo "  make config-backup    - Backup configuration files"
	@echo "  make config-restore   - Restore configuration from backup"
	@echo "  make config-validate  - Validate configuration files"
	@echo "  make config-summary   - Show configuration summary"

