# docker-compose.local.yml - TEST LOCAL sans Traefik
version: '3.8'

volumes:
  postgres_data_local:
  redis_data_local:
  api_data_local:
  license_data_local:

services:
  # ============================================================
  # API PRINCIPAL - TEST LOCAL
  # ============================================================
  web-sentinel-api:
    build:
      context: ../..
      dockerfile: deployment/Dockerfile.api.stripe
    container_name: web-sentinel-api-local
    restart: unless-stopped
    ports:
      - "5000:5000"  # Accès direct sans Traefik
    environment:
      - DATABASE_URL=postgresql://websentinel_user:${POSTGRES_PASSWORD}@web-sentinel-db:5432/websentinel_prod
      - WEB_SENTINEL_POSTGRES_URL=${DATABASE_URL}
      - WEB_SENTINEL_LICENSE_BACKEND=postgresql
      - REDIS_URL=redis://web-sentinel-redis:6379/0
      - FLASK_ENV=production
      - FLASK_DEBUG=False
      - WEB_SENTINEL_SECRET_KEY=${WEB_SENTINEL_SECRET_KEY}
      - STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY:-}
      - STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY:-}
      - STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET:-}
      - BASE_URL=http://localhost:8080
      - SMTP_HOST=${SMTP_HOST:-localhost}
      - SMTP_PORT=${SMTP_PORT:-587}
      - SMTP_USER=${SMTP_USER:-}
      - SMTP_PASSWORD=${SMTP_PASSWORD:-}
      - FROM_EMAIL=${FROM_EMAIL:-noreply@localhost}
      - FROM_NAME=${FROM_NAME:-Web Sentinel}
    volumes:
      - api_data_local:/app/data
      - license_data_local:/root/.web-sentinel
    depends_on:
      - web-sentinel-db
      - web-sentinel-redis

  # ============================================================
  # BASE DE DONNÉES
  # ============================================================
  web-sentinel-db:
    image: postgres:15-alpine
    container_name: web-sentinel-db-local
    restart: unless-stopped
    environment:
      - POSTGRES_USER=websentinel_user
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=websentinel_prod
    volumes:
      - postgres_data_local:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U websentinel_user -d websentinel_prod"]
      interval: 10s
      timeout: 5s
      retries: 3

  # ============================================================
  # CACHE Redis
  # ============================================================
  web-sentinel-redis:
    image: redis:7-alpine
    container_name: web-sentinel-redis-local
    restart: unless-stopped
    command: redis-server --appendonly yes
    volumes:
      - redis_data_local:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 3

  # ============================================================
  # SERVEUR SMTP
  # ============================================================
  web-sentinel-smtp:
    image: namshi/smtp:latest
    container_name: web-sentinel-smtp-local
    restart: unless-stopped

  # ============================================================
  # SITE WEB PRINCIPAL (nginx) - TEST LOCAL
  # ============================================================
  web-sentinel-web:
    image: nginx:alpine
    container_name: web-sentinel-web-local
    restart: unless-stopped
    ports:
      - "8090:80"  # Accès direct http://localhost:8090
    volumes:
      - ../../web:/usr/share/nginx/html

  # ============================================================
  # DOCUMENTATION (nginx) - TEST LOCAL
  # ============================================================
  web-sentinel-docs:
    image: nginx:alpine
    container_name: web-sentinel-docs-local
    restart: unless-stopped
    ports:
      - "8091:80"  # Accès direct http://localhost:8091
    volumes:
      - ../../docs:/usr/share/nginx/html

  # ============================================================
  # STATISTIQUES (nginx) - TEST LOCAL
  # ============================================================
  web-sentinel-stats:
    image: nginx:alpine
    container_name: web-sentinel-stats-local
    restart: unless-stopped
    ports:
      - "8082:80"  # Accès direct http://localhost:8082
    volumes:
      - ../../web/stats:/usr/share/nginx/html

  # ============================================================
  # INSTALLATION (nginx) - TEST LOCAL
  # ============================================================
  web-sentinel-install:
    image: nginx:alpine
    container_name: web-sentinel-install-local
    restart: unless-stopped
    ports:
      - "8083:80"  # Accès direct http://localhost:8083
    volumes:
      - ../../install:/usr/share/nginx/html
