# Makefile para Navegator

.PHONY: all build test test-unit test-e2e test-integration clean help

# Variables
BINARIES := screenshot buscar navegar
TEST_TIMEOUT := 300s

all: build test

## build: Compilar todos los binarios
build:
	@echo "🔨 Compilando binarios..."
	@mkdir -p bin
	@go build -o bin/screenshot cmd/screenshot.go
	@go build -o bin/buscar cmd/buscar.go
	@go build -o bin/navegar cmd/navegar.go
	@echo "✅ Binarios compilados en bin/"

## test: Ejecutar todos los tests
test: test-unit test-e2e test-integration
	@echo ""
	@echo "=========================================="
	@echo "✅ Todos los tests completados"
	@echo "=========================================="

## test-unit: Ejecutar tests unitarios de Go
test-unit:
	@echo "🧪 Ejecutando tests unitarios..."
	@go test -v -timeout $(TEST_TIMEOUT) ./pkg/browser/... ./pkg/cdp/... ./pkg/stealth/...

## test-e2e: Ejecutar tests E2E de binarios
test-e2e: build
	@echo "🎯 Ejecutando tests E2E..."
	@chmod +x e2e/e2e_test.sh
	@./e2e/e2e_test.sh

## test-integration: Ejecutar tests de integración
test-integration: build
	@echo "🔗 Ejecutando tests de integración..."
	@chmod +x e2e/integration_test.sh
	@./e2e/integration_test.sh

## test-quick: Tests rápidos (solo unitarios)
test-quick:
	@echo "⚡ Tests rápidos..."
	@go test -short ./pkg/...

## clean: Limpiar archivos generados
clean:
	@echo "🧹 Limpiando..."
	@rm -rf bin/ buscar-v2
	@rm -f *.png *.json *.log
	@rm -rf test-profiles/
	@rm -rf perfiles/test-*
	@rm -rf perfiles/*-clone-*
	@echo "✅ Limpieza completada"

## fmt: Formatear código Go
fmt:
	@echo "💅 Formateando código..."
	@go fmt ./...

## lint: Ejecutar linter
lint:
	@echo "🔍 Ejecutando linter..."
	@go vet ./...

## coverage: Generar reporte de cobertura
coverage:
	@echo "📊 Generando reporte de cobertura..."
	@go test -coverprofile=coverage.out ./pkg/...
	@go tool cover -html=coverage.out -o coverage.html
	@echo "✅ Reporte generado: coverage.html"

## bench: Ejecutar benchmarks
bench:
	@echo "⚡ Ejecutando benchmarks..."
	@go test -bench=. -benchmem ./pkg/...

## install: Instalar binarios en $GOPATH/bin
install: build
	@echo "📦 Instalando binarios..."
	@cp screenshot $(GOPATH)/bin/navegator-screenshot
	@cp buscar $(GOPATH)/bin/navegator-buscar
	@cp navegar $(GOPATH)/bin/navegator-navegar
	@echo "✅ Binarios instalados en $(GOPATH)/bin/"

## demo: Ejecutar demo de perfiles en paralelo
demo: build
	@chmod +x scripts/demo_paralelo.sh
	@./scripts/demo_paralelo.sh

## help: Mostrar ayuda
help:
	@echo "Navegator - Makefile Commands"
	@echo ""
	@echo "Uso: make [target]"
	@echo ""
	@echo "Targets disponibles:"
	@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'

.DEFAULT_GOAL := help
