# ============================================================
# CRM-Service - Standalone Entwicklungsumgebung
# ============================================================
# Startet PostgreSQL + Redis + CRM isoliert (ohne Core/Frontend)
#
# Starten:  docker compose -f docker-compose.crm-dev.yml up -d
# Stoppen:  docker compose -f docker-compose.crm-dev.yml down
# Logs:     docker compose -f docker-compose.crm-dev.yml logs -f crm
# Reset DB: docker compose -f docker-compose.crm-dev.yml down -v

services:
  crm-postgres:
    image: postgres:16-alpine
    container_name: crm-dev-postgres
    environment:
      POSTGRES_USER: insight
      POSTGRES_PASSWORD: devpassword
      POSTGRES_DB: platform_core
    ports:
      - "15432:5432"
    volumes:
      - crm-pg-data:/var/lib/postgresql/data
      - ./scripts/init-schema.sql:/docker-entrypoint-initdb.d/01-init-schema.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U insight -d platform_core"]
      interval: 5s
      timeout: 3s
      retries: 5

  crm-redis:
    image: redis:7-alpine
    container_name: crm-dev-redis
    ports:
      - "16379:6379"
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5

  crm:
    build:
      context: .
      dockerfile: Dockerfile
      target: development
    container_name: crm-dev-service
    environment:
      - NODE_ENV=development
      - APP_PORT=3100
      - DATABASE_URL=postgresql://insight:devpassword@crm-postgres:5432/platform_core?schema=app_crm
      - DATABASE_URL_DIRECT=postgresql://insight:devpassword@crm-postgres:5432/platform_core?schema=app_crm
      - REDIS_HOST=crm-redis
      - REDIS_PORT=6379
      - JWT_PUBLIC_KEY_PATH=/app/keys/jwt-public.pem
      - JWT_ISSUER=insight-platform
      - CORS_ORIGINS=http://localhost:3100,http://127.0.0.1:3100
    volumes:
      - .:/app
      - /app/node_modules
      - ./keys/jwt-public.pem:/app/keys/jwt-public.pem:ro
    ports:
      - "3100:3100"
    depends_on:
      crm-postgres:
        condition: service_healthy
      crm-redis:
        condition: service_healthy

volumes:
  crm-pg-data:
