# SAR — Stack de desenvolvimento local
# Alinhado com STACK.md JCS v2.2 (Postgres 18, Valkey, MinIO)
# Uso: pnpm dev:up | pnpm dev:down | pnpm dev:logs

services:
  postgres:
    image: postgres:18-alpine
    container_name: sar-postgres
    restart: unless-stopped
    environment:
      POSTGRES_USER: sar
      POSTGRES_PASSWORD: sar_dev_password
      POSTGRES_DB: sar_master
      # Inicializa também workspace de exemplo (default-workspace)
      # multi-tenancy real virá com master-login na próxima sessão
    ports:
      - '5432:5432'
    volumes:
      # Postgres 18+ usa /var/lib/postgresql (sem /data) — dados ficam em
      # subdir por major-version pra suportar pg_upgrade --link sem
      # boundary issues. Ref: docker-library/postgres#1259.
      - sar-postgres-data:/var/lib/postgresql
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U sar -d sar_master']
      interval: 10s
      timeout: 5s
      retries: 5

  valkey:
    image: valkey/valkey:8-alpine
    container_name: sar-valkey
    restart: unless-stopped
    command: valkey-server --save 60 1 --loglevel warning
    ports:
      - '6379:6379'
    volumes:
      - sar-valkey-data:/data
    healthcheck:
      test: ['CMD', 'valkey-cli', 'ping']
      interval: 10s
      timeout: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    container_name: sar-minio
    restart: unless-stopped
    command: server /data --console-address ':9001'
    environment:
      MINIO_ROOT_USER: sar_minio_admin
      MINIO_ROOT_PASSWORD: sar_minio_dev_password
    ports:
      - '9000:9000' # API S3-compat
      - '9001:9001' # Console web (http://localhost:9001)
    volumes:
      - sar-minio-data:/data
    healthcheck:
      test: ['CMD', 'curl', '-f', 'http://localhost:9000/minio/health/live']
      interval: 10s
      timeout: 5s
      retries: 5

  # Mailpit — captura emails locais (substitui Resend em dev)
  mailpit:
    image: axllent/mailpit:latest
    container_name: sar-mailpit
    restart: unless-stopped
    ports:
      - '1025:1025' # SMTP
      - '8025:8025' # Web UI (http://localhost:8025)

  # PostHog cloud-image-self-hosted? Por ora, deixar comentado.
  # No MVP, PostHog é instalado em VM/LXC Proxmox dedicada (separado do dev).

  # master-login stub? Por ora, deixar comentado.
  # JWT secret de dev será injetado via .env; master-login real virá na próxima sessão.

volumes:
  sar-postgres-data:
    name: sar-postgres-data
  sar-valkey-data:
    name: sar-valkey-data
  sar-minio-data:
    name: sar-minio-data

networks:
  default:
    name: sar-dev-network
    driver: bridge
