# docker-compose.stripe.yml - Configuration complète avec système de paiement Stripe
version: '3.8'

networks:
  faildaily-ssl-network:
    external: 
      name: faildaily_faildaily-ssl-network
  web-sentinel:
    driver: bridge

volumes:
  postgres_data:
  redis_data:
  license_data:

services:
  # API Principal avec Stripe et Licences
  web-sentinel-api:
    build:
      context: ..
      dockerfile: deployment/Dockerfile.api.stripe
    container_name: web-sentinel-api
    restart: unless-stopped
    environment:
      # Database
      - 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
      - FLASK_ENV=production
      - FLASK_DEBUG=False
      - WEB_SENTINEL_SECRET_KEY=${WEB_SENTINEL_SECRET_KEY}
      
      # Stripe
      - STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}
      - STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}
      - STRIPE_WEBHOOK_SECRET=${STRIPE_WEBHOOK_SECRET}
      - BASE_URL=https://web-sentinel.taaazzz-prog.fr
      
      # Email SMTP (via service email interne)
      - SMTP_HOST=web-sentinel-smtp
      - SMTP_PORT=587
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASSWORD=${SMTP_PASSWORD}
      - FROM_EMAIL=${FROM_EMAIL:-noreply@web-sentinel.taaazzz-prog.fr}
      - FROM_NAME=Web Sentinel
    volumes:
      - license_data:/root/.web-sentinel
    networks:
      - faildaily-ssl-network
      - web-sentinel
    depends_on:
      - web-sentinel-db
      - web-sentinel-redis
      - web-sentinel-smtp
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-api.rule=Host(`api.web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-api.entrypoints=websecure"
      - "traefik.http.routers.web-sentinel-api.tls=true"
      - "traefik.http.routers.web-sentinel-api.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-api.loadbalancer.server.port=5000"

  # Base de données PostgreSQL
  web-sentinel-db:
    image: postgres:15-alpine
    container_name: web-sentinel-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=websentinel_user
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=websentinel_prod
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - web-sentinel
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U websentinel_user -d websentinel_prod"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Redis pour cache et sessions
  web-sentinel-redis:
    image: redis:7-alpine
    container_name: web-sentinel-redis
    restart: unless-stopped
    volumes:
      - redis_data:/data
    networks:
      - web-sentinel
    command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru

  # Serveur SMTP pour emails transactionnels
  web-sentinel-smtp:
    image: namshi/smtp:latest
    container_name: web-sentinel-smtp
    restart: unless-stopped
    environment:
      # Relais SMTP vers Gmail/SendGrid/etc
      - RELAY_NETWORKS=:192.168.0.0/16:172.16.0.0/12:10.0.0.0/8
      - SMARTHOST_ADDRESS=${SMTP_RELAY_HOST:-smtp.gmail.com}
      - SMARTHOST_PORT=${SMTP_RELAY_PORT:-587}
      - SMARTHOST_USER=${SMTP_USER}
      - SMARTHOST_PASSWORD=${SMTP_PASSWORD}
      - SMARTHOST_ALIASES=*.web-sentinel.taaazzz-prog.fr
    networks:
      - web-sentinel
    healthcheck:
      test: ["CMD", "nc", "-z", "localhost", "25"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Site web statique (pages de paiement)
  web-sentinel-web:
    image: nginx:alpine
    container_name: web-sentinel-web
    restart: unless-stopped
    volumes:
      - ../web:/usr/share/nginx/html:ro
      - ./nginx-web.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - faildaily-ssl-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-web.rule=Host(`web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-web.tls=true"
      - "traefik.http.routers.web-sentinel-web.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-web.loadbalancer.server.port=80"

  # Documentation
  web-sentinel-docs:
    image: nginx:alpine
    container_name: web-sentinel-docs
    restart: unless-stopped
    volumes:
      - ../docs:/usr/share/nginx/html:ro
      - ./nginx-docs.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - faildaily-ssl-network
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.web-sentinel-docs.rule=Host(`docs.web-sentinel.taaazzz-prog.fr`)"
      - "traefik.http.routers.web-sentinel-docs.tls=true"
      - "traefik.http.routers.web-sentinel-docs.tls.certresolver=letsencrypt"
      - "traefik.http.services.web-sentinel-docs.loadbalancer.server.port=80"
