# LocalGreenChain Development Docker Compose
# Agent 4: Production Deployment
# Development environment with hot reloading and debug tools

version: '3.8'

services:
  # ==========================================================================
  # Application (Development Mode)
  # ==========================================================================
  app:
    build:
      context: .
      dockerfile: Dockerfile
      target: deps  # Use deps stage for development
    container_name: lgc-app-dev
    restart: unless-stopped
    ports:
      - "${PORT:-3001}:3001"
    environment:
      - NODE_ENV=development
      - DATABASE_URL=postgresql://lgc:lgc_dev_password@postgres:5432/localgreenchain_dev
      - REDIS_URL=redis://redis:6379
      - LOG_LEVEL=debug
      - PLANTS_NET_API_KEY=${PLANTS_NET_API_KEY:-}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    volumes:
      # Mount source code for hot reloading
      - .:/app
      - /app/node_modules  # Exclude node_modules
      - /app/.next         # Exclude build output
    networks:
      - lgc-dev-network
    command: bun run dev

  # ==========================================================================
  # Database (Development)
  # ==========================================================================
  postgres:
    image: postgres:15-alpine
    container_name: lgc-postgres-dev
    restart: unless-stopped
    environment:
      - POSTGRES_USER=lgc
      - POSTGRES_PASSWORD=lgc_dev_password
      - POSTGRES_DB=localgreenchain_dev
    volumes:
      - postgres-dev-data:/var/lib/postgresql/data
    ports:
      - "5433:5432"  # Different port to avoid conflicts
    networks:
      - lgc-dev-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U lgc -d localgreenchain_dev"]
      interval: 5s
      timeout: 5s
      retries: 5

  # ==========================================================================
  # Cache (Development)
  # ==========================================================================
  redis:
    image: redis:7-alpine
    container_name: lgc-redis-dev
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - redis-dev-data:/data
    ports:
      - "6380:6379"  # Different port to avoid conflicts
    networks:
      - lgc-dev-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 5

  # ==========================================================================
  # Database Admin (pgAdmin)
  # ==========================================================================
  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: lgc-pgadmin-dev
    restart: unless-stopped
    environment:
      - PGADMIN_DEFAULT_EMAIL=admin@localgreenchain.local
      - PGADMIN_DEFAULT_PASSWORD=admin
      - PGADMIN_CONFIG_SERVER_MODE=False
    volumes:
      - pgadmin-dev-data:/var/lib/pgadmin
    ports:
      - "5050:80"
    networks:
      - lgc-dev-network
    depends_on:
      - postgres
    profiles:
      - tools

  # ==========================================================================
  # Redis Commander (Redis UI)
  # ==========================================================================
  redis-commander:
    image: rediscommander/redis-commander:latest
    container_name: lgc-redis-commander-dev
    restart: unless-stopped
    environment:
      - REDIS_HOSTS=local:redis:6379
    ports:
      - "8081:8081"
    networks:
      - lgc-dev-network
    depends_on:
      - redis
    profiles:
      - tools

  # ==========================================================================
  # MailHog (Email Testing)
  # ==========================================================================
  mailhog:
    image: mailhog/mailhog:latest
    container_name: lgc-mailhog-dev
    restart: unless-stopped
    ports:
      - "1025:1025"  # SMTP
      - "8025:8025"  # Web UI
    networks:
      - lgc-dev-network
    profiles:
      - tools

# =============================================================================
# Networks
# =============================================================================
networks:
  lgc-dev-network:
    driver: bridge
    name: lgc-dev-network

# =============================================================================
# Volumes
# =============================================================================
volumes:
  postgres-dev-data:
    name: lgc-postgres-dev-data
  redis-dev-data:
    name: lgc-redis-dev-data
  pgadmin-dev-data:
    name: lgc-pgadmin-dev-data
