##############################################################################
# Beconnect — docker-compose.dev.yml
# Stack mínima para desenvolvimento local
# Uso: docker compose -f docker-compose.dev.yml up -d
##############################################################################

services:

  # MySQL — base de dados local
  mysql:
    image: mysql:8.0
    container_name: beconnect_dev_mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: beconnect
      MYSQL_USER: beconnect
      MYSQL_PASSWORD: beconnect_secret
    ports:
      - "3306:3306"
    volumes:
      - beconnect_dev_mysql:/var/lib/mysql
    networks:
      - beconnect_dev
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-uroot", "-proot"]
      interval: 10s
      timeout: 5s
      retries: 10

  # Redis — cache e sessões
  redis:
    image: redis:7-alpine
    container_name: beconnect_dev_redis
    restart: unless-stopped
    ports:
      - "6379:6379"
    networks:
      - beconnect_dev
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5

  # Laravel — API + backend
  app:
    build:
      context: .
      dockerfile: docker/php/Dockerfile
    container_name: beconnect_dev_app
    restart: unless-stopped
    working_dir: /var/www
    volumes:
      - .:/var/www
      - ./docker/php/local.ini:/usr/local/etc/php/conf.d/local.ini
    ports:
      - "8000:8000"
    environment:
      APP_ENV: local
      APP_DEBUG: "true"
      APP_URL: http://localhost:8000
      DB_CONNECTION: mysql
      DB_HOST: mysql
      DB_PORT: 3306
      DB_DATABASE: beconnect
      DB_USERNAME: beconnect
      DB_PASSWORD: beconnect_secret
      REDIS_HOST: redis
      REDIS_PORT: 6379
      CACHE_STORE: redis
      SESSION_DRIVER: redis
      QUEUE_CONNECTION: redis
      MAIL_MAILER: smtp
      MAIL_HOST: mailpit
      MAIL_PORT: 1025
      MAIL_FROM_ADDRESS: noreply@beconnect.local
    command: >
      sh -c "php artisan migrate --force &&
             php artisan optimize &&
             php artisan serve --host=0.0.0.0 --port=8000"
    depends_on:
      mysql:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - beconnect_dev

  # Mailpit — captura de emails (UI em :8025)
  mailpit:
    image: axllent/mailpit:latest
    container_name: beconnect_dev_mailpit
    restart: unless-stopped
    ports:
      - "8025:8025"
      - "1025:1025"
    networks:
      - beconnect_dev

  # phpMyAdmin — gestão da BD (acesso em :8084)
  phpmyadmin:
    image: phpmyadmin:latest
    container_name: beconnect_dev_phpmyadmin
    restart: unless-stopped
    ports:
      - "8084:80"
    environment:
      PMA_HOST: mysql
      PMA_PORT: 3306
      PMA_USER: beconnect
      PMA_PASSWORD: beconnect_secret
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - beconnect_dev

networks:
  beconnect_dev:
    driver: bridge

volumes:
  beconnect_dev_mysql:
