services:
  mysql:
    image: mysql:8.4
    container_name: lcc-mysql-local
    env_file:
      - .env.mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: lcc
      MYSQL_USER: ${SPRING_DATASOURCE_USERNAME}
      MYSQL_PASSWORD: ${SPRING_DATASOURCE_PASSWORD}
    volumes:
      - mysql-data-local:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - lcc-network-local
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 5s
      retries: 5
    restart: unless-stopped

  # MSSQL Database (optional - nur für MSSQL-Tests)
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    container_name: lcc-mssql-local
    environment:
      ACCEPT_EULA: "Y"
      MSSQL_SA_PASSWORD: ${DB_ROOT_PASSWORD}
      MSSQL_PID: "Developer"
    volumes:
      - mssql-data-local:/var/opt/mssql
    ports:
      - "1433:1433"
    networks:
      - lcc-network-local
    healthcheck:
      test: /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P "$${MSSQL_SA_PASSWORD}" -Q "SELECT 1" -C || exit 1
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 30s
    restart: unless-stopped
    profiles:
      - mssql  # Startet nur mit: docker-compose --profile mssql up

  lcc-app:
    #image: git.avatic.de/avatic/lcc:latest
    # Oder für lokales Bauen:
    build: .
    container_name: lcc-app-local
    depends_on:
      mysql:
        condition: service_healthy
    env_file:
      - .env.mysql
    environment:
      # Überschreibe die Datasource URL für Docker-Netzwerk
      SPRING_DATASOURCE_URL: jdbc:mysql://mysql:3306/lcc
    ports:
      - "8080:8080"
    networks:
      - lcc-network-local
    dns:
      - 8.8.8.8
      - 8.8.4.4
    restart: unless-stopped

volumes:
  mysql-data-local:
  mssql-data-local:

networks:
  lcc-network-local:
    driver: bridge