services:
  web:
    build: .
    container_name: may
    restart: unless-stopped
    ports:
      - "8234:8080"
    environment:
      # Token de API de EasyAppointments. Definido en .env (ver .env.example).
      - EA_API_KEY=${EA_API_KEY}
      # Opcional: fija el provider; vacío = autodescubierto en EA.
      - EA_PROVIDER_ID=${EA_PROVIDER_ID:-}
    depends_on:
      - easyappointments

  # EasyAppointments - gestión de citas, clientes y servicios
  easyappointments:
    image: alextselegidis/easyappointments:latest
    container_name: may-easyappointments
    restart: unless-stopped
    ports:
      - "8888:80"   # Panel admin: http://localhost:8888
    depends_on:
      mysql:
        condition: service_healthy
    environment:
      - BASE_URL=${EA_BASE_URL:-http://localhost:8888}
      - DEBUG_MODE=FALSE
      - DB_HOST=mysql
      - DB_NAME=easyappointments
      - DB_USERNAME=root
      - DB_PASSWORD=${MYSQL_ROOT_PASSWORD}

  mysql:
    image: mysql:8.0
    container_name: may-ea-mysql
    restart: unless-stopped
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=easyappointments
    healthcheck:
      # EA solo arranca bien si MySQL ya está listo (no solo "iniciado").
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -u root -p\"$$MYSQL_ROOT_PASSWORD\" --silent"]
      interval: 10s
      timeout: 5s
      retries: 10
    volumes:
      - ea-mysql-data:/var/lib/mysql

volumes:
  ea-mysql-data:
