services:
  mysql:
    image: mysql:8.0
    container_name: shreeclass-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-root}
      MYSQL_DATABASE: ${DB_NAME:-shreeclass_attendance}
      MYSQL_USER: ${DB_USERNAME:-shreeclass}
      MYSQL_PASSWORD: ${DB_PASSWORD:-shreeclass}
    ports:
      - "3306:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-p${DB_ROOT_PASSWORD:-root}"]
      interval: 10s
      timeout: 5s
      retries: 10

  backend:
    build:
      context: .
      dockerfile: docker/backend.Dockerfile
    container_name: shreeclass-backend
    restart: unless-stopped
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      SPRING_PROFILES_ACTIVE: docker
      DB_HOST: mysql
      DB_PORT: 3306
      DB_NAME: ${DB_NAME:-shreeclass_attendance}
      DB_USERNAME: ${DB_USERNAME:-shreeclass}
      DB_PASSWORD: ${DB_PASSWORD:-shreeclass}
      JWT_SECRET: ${JWT_SECRET:-ZmFrZS1kZXYtb25seS1zZWNyZXQta2V5LWNoYW5nZS1pbi1wcm9kdWN0aW9uLTIwMjY=}
      WHATSAPP_PHONE_NUMBER_ID: ${WHATSAPP_PHONE_NUMBER_ID:-}
      WHATSAPP_ACCESS_TOKEN: ${WHATSAPP_ACCESS_TOKEN:-}
      WHATSAPP_TEMPLATE_IN: ${WHATSAPP_TEMPLATE_IN:-student_checkin}
      WHATSAPP_TEMPLATE_OUT: ${WHATSAPP_TEMPLATE_OUT:-student_checkout}
    ports:
      - "8080:8080"
    volumes:
      - student_photos:/app/uploads/students

  frontend:
    build:
      context: .
      dockerfile: docker/frontend.Dockerfile
    container_name: shreeclass-frontend
    restart: unless-stopped
    depends_on:
      - backend
    ports:
      - "80:80"

volumes:
  mysql_data:
  student_photos:
