services:
  postgres:
    build:
      context: ../v2_postgres
    container_name: db
    restart: always
    env_file: .env
    environment:
      POSTGRES_HOST: postgres
      POSTGRES_INITDB_ARGS: '--encoding=UTF8 --locale=de_DE.UTF-8'
      POSTGRES_COLLATE: 'de_DE.UTF-8'
      POSTGRES_CTYPE: 'de_DE.UTF-8'
      TZ: Europe/Berlin
      PGTZ: Europe/Berlin
    volumes:
      # Persistente Speicherung der Datenbank auf dem Windows-Host
      - postgres_data:/var/lib/postgresql/data
      # Init-Skript für Tabellen
      - ../v2_adminpanel/init.sql:/docker-entrypoint-initdb.d/init.sql
    networks:
      - internal_net
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4g

  license-server:
    build:
      context: ../v2_lizenzserver
    container_name: license-server
    restart: always
    # Port-Mapping entfernt - nur noch über Nginx erreichbar
    env_file: .env
    environment:
      TZ: Europe/Berlin
    depends_on:
      - postgres
    networks:
      - internal_net
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4g

  # auth-service:
  #   build:
  #     context: ../lizenzserver/services/auth
  #   container_name: auth-service
  #   restart: always
  #   # Port 5001 - nur intern erreichbar
  #   env_file: .env
  #   environment:
  #     TZ: Europe/Berlin
  #     DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/v2_adminpanel
  #     REDIS_URL: redis://redis:6379/1
  #     JWT_SECRET: ${JWT_SECRET}
  #     FLASK_ENV: production
  #   depends_on:
  #     - postgres
  #     - redis
  #   networks:
  #     - internal_net
  #   deploy:
  #     resources:
  #       limits:
  #         cpus: '1'
  #         memory: 1g

  # analytics-service:
  #   build:
  #     context: ../lizenzserver/services/analytics
  #   container_name: analytics-service
  #   restart: always
  #   # Port 5003 - nur intern erreichbar
  #   env_file: .env
  #   environment:
  #     TZ: Europe/Berlin
  #     DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/v2_adminpanel
  #     REDIS_URL: redis://redis:6379/2
  #     JWT_SECRET: ${JWT_SECRET}
  #     FLASK_ENV: production
  #   depends_on:
  #     - postgres
  #     - redis
  #     - rabbitmq
  #   networks:
  #     - internal_net
  #   deploy:
  #     resources:
  #       limits:
  #         cpus: '1'
  #         memory: 2g

  # admin-api-service:
  #   build:
  #     context: ../lizenzserver/services/admin_api
  #   container_name: admin-api-service
  #   restart: always
  #   # Port 5004 - nur intern erreichbar
  #   env_file: .env
  #   environment:
  #     TZ: Europe/Berlin
  #     DATABASE_URL: postgresql://postgres:${POSTGRES_PASSWORD}@postgres:5432/v2_adminpanel
  #     REDIS_URL: redis://redis:6379/3
  #     JWT_SECRET: ${JWT_SECRET}
  #     FLASK_ENV: production
  #   depends_on:
  #     - postgres
  #     - redis
  #     - rabbitmq
  #   networks:
  #     - internal_net
  #   deploy:
  #     resources:
  #       limits:
  #         cpus: '1'
  #         memory: 2g

  admin-panel:
    build:
      context: ../v2_adminpanel
    container_name: admin-panel
    restart: always
    # Port-Mapping entfernt - nur über nginx erreichbar
    env_file: .env
    environment:
      TZ: Europe/Berlin
    depends_on:
      - postgres
    networks:
      - internal_net
    volumes:
      # Backup-Verzeichnis
      - ../backups:/app/backups
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 4g

  nginx:
    build:
      context: ../v2_nginx
    container_name: nginx-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    environment:
      TZ: Europe/Berlin
    depends_on:
      - admin-panel
      - license-server
    networks:
      - internal_net

networks:
  internal_net:
    driver: bridge

volumes:
  postgres_data:
