#!/bin/bash
# Quick build status checker
# Usage: ./scripts/build-status.sh

# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'

if ! docker ps --filter name=pigen_work --format "{{.Status}}" &>/dev/null; then
    echo -e "${RED}Docker not available${NC}"
    exit 1
fi

STATUS=$(docker ps --filter name=pigen_work --format "{{.Status}}")

if [ -z "$STATUS" ]; then
    echo -e "${YELLOW}No build running${NC}"
    echo "Start a build with: ./build-image.sh full"
    exit 0
fi

echo -e "${GREEN}Build Status:${NC} $STATUS"
echo ""
echo -e "${BLUE}Current Stage:${NC}"
docker logs pigen_work 2>&1 | grep -E "^\[.*\] Begin /pi-gen/(stage[^/]+)" | tail -1

echo ""
echo -e "${BLUE}Recent Progress (last 10 steps):${NC}"
docker logs pigen_work 2>&1 | grep -E "^\[.*\] (Begin|End)" | tail -10

echo ""
echo -e "${BLUE}Latest Activity:${NC}"
docker logs --tail 3 pigen_work 2>&1

echo ""
echo -e "Watch live: ${YELLOW}docker logs -f pigen_work${NC}"
