services:
  app:
    build: .
    container_name: crm_app
    restart: unless-stopped
    ports:
      - "${APP_PORT:-8080}:80"
    volumes:
      - crm_storage:/var/www/storage/app
      - ./.env:/var/www/.env
    environment:
      DB_HOST: db
      DB_PORT: 3306
      DB_DATABASE: ${DB_DATABASE:-crm}
      DB_USERNAME: ${DB_USERNAME:-crm}
      DB_PASSWORD: ${DB_PASSWORD:-changeme}
      APP_URL: ${APP_URL:-http://localhost:8080}
    depends_on:
      db:
        condition: service_healthy
    networks: [crm_net]

  db:
    image: mysql:8.0
    container_name: crm_db
    restart: unless-stopped
    environment:
      MYSQL_DATABASE: ${DB_DATABASE:-crm}
      MYSQL_USER: ${DB_USERNAME:-crm}
      MYSQL_PASSWORD: ${DB_PASSWORD:-changeme}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD:-changeme_root}
    volumes:
      - crm_db_data:/var/lib/mysql
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 5s
      timeout: 5s
      retries: 10
    networks: [crm_net]

volumes:
  crm_db_data:
  crm_storage:

networks:
  crm_net:
