# TaskMaster Makefile

.PHONY: build run test clean help install deps fmt vet check coverage build-all

# Binary name
BINARY=taskmaster
BUILD_DIR=bin

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOCLEAN=$(GOCMD) clean
GOMOD=$(GOCMD) mod

# Build the application
build:
	@echo "Building $(BINARY)..."
	@mkdir -p $(BUILD_DIR)
	$(GOBUILD) -o $(BUILD_DIR)/$(BINARY) ./cmd/taskmaster
	@echo "Build complete: $(BUILD_DIR)/$(BINARY)"

# Run the application
run: build
	@$(BUILD_DIR)/$(BINARY)

# Run tests
test:
	@echo "Running tests..."
	$(GOTEST) -v -race -coverprofile=coverage.out ./...
	@echo "Coverage report: coverage.out"

# Run tests with coverage report
coverage: test
	$(GOCMD) tool cover -html=coverage.out -o coverage.html
	@echo "Coverage HTML report: coverage.html"

# Clean build artifacts
clean:
	@echo "Cleaning..."
	$(GOCLEAN)
	rm -rf $(BUILD_DIR)
	rm -f coverage.out coverage.html
	rm -f tasks.db test_tasks.db
	@echo "Clean complete"

# Install dependencies
deps:
	@echo "Downloading dependencies..."
	$(GOMOD) download
	$(GOMOD) tidy

# Format code
fmt:
	@echo "Formatting code..."
	gofmt -w .

# Vet code
vet:
	@echo "Vetting code..."
	$(GOCMD) vet ./...

# Run all checks
check: fmt vet test

# Install the binary
install: build
	@echo "Installing $(BINARY) to $(GOPATH)/bin..."
	cp $(BUILD_DIR)/$(BINARY) $(GOPATH)/bin/

# Build for multiple platforms
build-all:
	@echo "Building for multiple platforms..."
	GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY)-linux-amd64 ./cmd/taskmaster
	GOOS=darwin GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY)-darwin-amd64 ./cmd/taskmaster
	GOOS=windows GOARCH=amd64 $(GOBUILD) -o $(BUILD_DIR)/$(BINARY)-windows-amd64.exe ./cmd/taskmaster
	@echo "Multi-platform build complete"

# Help
help:
	@echo "TaskMaster Build Commands:"
	@echo "  make build      - Build the application"
	@echo "  make run        - Build and run the application"
	@echo "  make test       - Run tests"
	@echo "  make coverage   - Generate coverage report"
	@echo "  make clean      - Clean build artifacts"
	@echo "  make deps       - Download dependencies"
	@echo "  make fmt        - Format code"
	@echo "  make vet        - Vet code"
	@echo "  make check      - Run fmt, vet, and test"
	@echo "  make install    - Install binary to GOPATH"
	@echo "  make build-all  - Build for multiple platforms"
