version: '3.8'

services:
  # PostgreSQL Database
  postgres:
    image: postgres:16-alpine
    container_name: trading_bot_db
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${DB_USER:-trading_bot}
      POSTGRES_PASSWORD: ${DB_PASSWORD:-trading_bot_2026}
      POSTGRES_DB: ${DB_NAME:-trading_db}
      TZ: Asia/Jakarta
    ports:
      - "${DB_PORT:-5432}:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./docker/init-db:/docker-entrypoint-initdb.d:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-trading_bot} -d ${DB_NAME:-trading_db}"]
      interval: 10s
      timeout: 5s
      retries: 5

  # pgAdmin (Optional - for database management)
  pgadmin:
    image: dpage/pgadmin4:latest
    container_name: trading_bot_pgadmin
    restart: unless-stopped
    environment:
      PGADMIN_DEFAULT_EMAIL: ${PGADMIN_EMAIL:-admin@trading.local}
      PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD:-admin123}
      PGADMIN_CONFIG_SERVER_MODE: 'False'
    ports:
      - "${PGADMIN_PORT:-5050}:80"
    volumes:
      - pgadmin_data:/var/lib/pgadmin
    depends_on:
      postgres:
        condition: service_healthy
    profiles:
      - admin  # Only start with: docker-compose --profile admin up

volumes:
  postgres_data:
    name: trading_bot_postgres_data
  pgadmin_data:
    name: trading_bot_pgadmin_data

networks:
  default:
    name: trading_bot_network
