#!/bin/bash

# Colors for terminal output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

echo -e "${BLUE}=== Starting Postaci Development Environment ===${NC}"

# Current directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# Start the address validation service in the background
echo -e "${YELLOW}Starting address validation service...${NC}"
cd "$SCRIPT_DIR/validation-service" && \
  node server.js > validation-service.log 2>&1 &

VALIDATION_PID=$!
echo -e "${GREEN}✓ Address validation service started (PID: $VALIDATION_PID)${NC}"

# Give the validation service a moment to start
sleep 1

# Start Next.js app
echo -e "${YELLOW}Starting Next.js application...${NC}"
cd "$SCRIPT_DIR" && npm run dev

# When Next.js is stopped, also stop the validation service
echo -e "${YELLOW}Stopping address validation service (PID: $VALIDATION_PID)...${NC}"
kill $VALIDATION_PID
echo -e "${GREEN}✓ Development environment shut down${NC}" 