services:

  app:
    build: .
    ports:
      - "8080:80"
    environment:
      APP_ENV: ${APP_ENV:-production}
      DB_HOST: db
      DB_NAME: ${DB_NAME:-axioma}
      DB_USER: ${DB_USER:-axioma}
      DB_PASS: ${DB_PASS}
      REDIS_HOST: redis
      REDIS_PORT: 6379
      # Read by laravel/config/session.php (Laravel's own session cookie) and
      # App\Support\SessionAuth::cookieDomain() (the hand-rolled remember-me
      # cookie) — each request runs as its own PHP process, so this has to be
      # a real container env var, not just a value in .env that a script's
      # own dotenv loader putenv()'s for itself.
      SESSION_COOKIE_DOMAIN: ${SESSION_COOKIE_DOMAIN:-}
    volumes:
      # Mount source for local development — remove in production
      - .:/var/www/html
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped

  db:
    image: mysql:8.0
    environment:
      MYSQL_DATABASE: ${DB_NAME:-axioma}
      MYSQL_USER: ${DB_USER:-axioma}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
    volumes:
      # Persist DB data between restarts
      - db_data:/var/lib/mysql
      # Auto-run migrations on first start
      - ./docker/mysql/init:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "axioma", "-p${DB_PASS}"]
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 5s
      retries: 10
    restart: unless-stopped

  bot:
    build: ${BOT_BUILD_CONTEXT:-../teacher_reminder_bot}
    environment:
      BOT_TOKEN: ${BOT_TOKEN}
      ADMIN_IDS: ${ADMIN_IDS}
      DB_HOST: db
      DB_NAME: ${DB_NAME:-axioma}
      DB_USER: ${DB_USER:-axioma}
      DB_PASS: ${DB_PASS}
      TIMEZONE: ${APP_TZ:-Asia/Almaty}
    depends_on:
      db:
        condition: service_healthy
    restart: unless-stopped

volumes:
  db_data:
