#!/usr/bin/env bash
set -euo pipefail

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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TEMPLATES_DIR="${SCRIPT_DIR}/../templates"

echo -e "${BLUE}=== Production Dockerfile Generator ===${NC}\n"

show_menu() {
    echo -e "${GREEN}Select your tech stack:${NC}"
    echo "  1) Python - Flask"
    echo "  2) Python - FastAPI"
    echo "  3) Node.js - Express"
    echo "  4) Go - Application"
    echo "  5) Exit"
    echo
}

while true; do
    show_menu
    read -rp "Enter choice [1-5]: " choice

    case $choice in
        1)
            cp "$TEMPLATES_DIR/python/flask.Dockerfile" Dockerfile
            echo -e "${GREEN}✓ Flask Dockerfile created${NC}"
            echo -e "\n${YELLOW}Next: Create requirements.txt with: flask, gunicorn${NC}"
            break
            ;;
        2)
            cp "$TEMPLATES_DIR/python/fastapi.Dockerfile" Dockerfile
            echo -e "${GREEN}✓ FastAPI Dockerfile created${NC}"
            echo -e "\n${YELLOW}Next: Create requirements.txt with: fastapi, uvicorn[standard]${NC}"
            break
            ;;
        3)
            cp "$TEMPLATES_DIR/node/express.Dockerfile" Dockerfile
            echo -e "${GREEN}✓ Express Dockerfile created${NC}"
            echo -e "\n${YELLOW}Next: Ensure package.json exists${NC}"
            break
            ;;
        4)
            cp "$TEMPLATES_DIR/go/multi-stage.Dockerfile" Dockerfile
            echo -e "${GREEN}✓ Go Dockerfile created${NC}"
            echo -e "\n${YELLOW}Next: Ensure go.mod exists${NC}"
            break
            ;;
        5)
            exit 0
            ;;
        *)
            echo -e "${RED}Invalid choice${NC}\n"
            ;;
    esac
done

echo -e "\n${BLUE}Build: docker build -t myapp .${NC}"
echo -e "${BLUE}Validate: ./scripts/validate-dockerfile.sh${NC}"
