version: '3.8'

services:
  # Infrastructure
  nats:
    image: nats:latest
    ports:
      - "4222:4222"
      - "8222:8222"
    command: ["-js"]

  postgres-master:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: master_db
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
    ports:
      - "5432:5432"

  timescaledb:
    image: timescale/timescaledb:latest-pg15
    environment:
      POSTGRES_DB: telemetry_db
      POSTGRES_USER: admin
      POSTGRES_PASSWORD: password
    ports:
      - "5433:5432"

  # Backend Services
  gateway:
    build:
      context: .
      dockerfile: deployments/docker/Gateway.Dockerfile
    volumes:
      - .:/app
    environment:
      - NATS_URL=nats://nats:4222
      - DB_URL=postgres://admin:password@postgres-master:5432/master_db?sslmode=disable
    ports:
      - "8080:8080"
    depends_on:
      - nats
      - postgres-master

  storage-node:
    build:
      context: .
      dockerfile: deployments/docker/Storage.Dockerfile
    volumes:
      - .:/app
    environment:
      - NATS_URL=nats://nats:4222
      - DB_URL=postgres://admin:password@postgres-master:5432/master_db?sslmode=disable
    depends_on:
      - nats
      - postgres-master

  # Customer Worker Simulation
  worker:
    build:
      context: .
      dockerfile: deployments/docker/Worker.Dockerfile
    volumes:
      - .:/app
    environment:
      - GATEWAY_URL=ws://gateway:8080/ws?role=worker
      - MOCK_MODE=true
    depends_on:
      - gateway

  # Discord Bot (Managed Trust)
  discord-bot:
    build:
      context: .
      dockerfile: deployments/docker/DiscordBot.Dockerfile
    volumes:
      - .:/app
    environment:
      - NATS_URL=nats://nats:4222
      - DISCORD_TOKEN=${DISCORD_TOKEN:-demo-token}
    depends_on:
      - nats
      - gateway

  # Frontend Dashboard
  dashboard:
    build:
      context: ./web/dashboard
      dockerfile: ../../deployments/docker/Dashboard.Dockerfile
    ports:
      - "5173:5173"
    volumes:
      - ./web/dashboard:/app
      - /app/node_modules
    environment:
      - VITE_GATEWAY_URL=ws://localhost:8080/ws
