.PHONY: all clean dev-operator dev-portal test lint build

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
BINARY_NAME=container-mom

# Directories
CMD_DIR=cmd
PKG_DIR=pkg
BUILD_DIR=build

# Development server ports
OPERATOR_PORT=8080
PORTAL_PORT=3000

all: test build

clean:
	$(GOCLEAN)
	rm -f $(BUILD_DIR)/*

deps:
	$(GOMOD) download
	$(GOMOD) tidy

# Development commands
dev-operator:
	@echo "Starting operator in development mode..."
	$(GOCMD) run $(CMD_DIR)/operator/main.go

dev-portal:
	@echo "Starting web portal in development mode..."
	$(GOCMD) run $(CMD_DIR)/portal/main.go

# Build commands
build-operator:
	$(GOBUILD) -o $(BUILD_DIR)/operator $(CMD_DIR)/operator/main.go

build-portal:
	$(GOBUILD) -o $(BUILD_DIR)/portal $(CMD_DIR)/portal/main.go

build: build-operator build-portal

# Test commands
test:
	$(GOTEST) -v ./...

test-coverage:
	$(GOTEST) -v -coverprofile=coverage.out ./...
	$(GOCMD) tool cover -html=coverage.out

# Lint commands
lint:
	golangci-lint run

# Docker commands
docker-build-operator:
	docker build -t container-mom-operator:local -f build/Dockerfile.operator .

docker-build-portal:
	docker build -t container-mom-portal:local -f build/Dockerfile.portal .

docker-run-operator:
	docker run -p $(OPERATOR_PORT):8080 container-mom-operator:local

docker-run-portal:
	docker run -p $(PORTAL_PORT):3000 container-mom-portal:local

# Development environment setup
dev-setup:
	@echo "Setting up development environment..."
	$(GOGET) -u golang.org/x/tools/cmd/goimports
	$(GOGET) -u github.com/golangci/golangci-lint/cmd/golangci-lint
	$(MAKE) deps

# Run all components locally
dev-all:
	@echo "Starting all components in development mode..."
	$(MAKE) dev-operator & $(MAKE) dev-portal

# Help command
help:
	@echo "Available commands:"
	@echo "  make dev-operator    - Run the operator locally"
	@echo "  make dev-portal      - Run the web portal locally"
	@echo "  make dev-all         - Run all components locally"
	@echo "  make build           - Build all binaries"
	@echo "  make test            - Run tests"
	@echo "  make lint            - Run linter"
	@echo "  make docker-build-operator - Build operator Docker image"
	@echo "  make docker-build-portal   - Build portal Docker image"
	@echo "  make docker-run-operator   - Run operator in Docker"
	@echo "  make docker-run-portal     - Run portal in Docker"
	@echo "  make dev-setup      - Setup development environment"
	@echo "  make clean          - Clean build artifacts" 