services:
  # ==========================================
  # 1. Laravel Application (PHP-FPM)
  # ==========================================
  app:
    build:
      context: .
      dockerfile: docker/Dockerfile
    restart: unless-stopped
    environment:
      APP_NAME: ${APP_NAME:-Laravel}
      APP_ENV: ${APP_ENV:-production}
      APP_KEY: ${APP_KEY}
      APP_DEBUG: ${APP_DEBUG:-false}
      APP_URL: ${APP_URL}

      DB_CONNECTION: pgsql
      DB_HOST: db
      DB_PORT: 5432

      DB_DATABASE: ${DB_DATABASE}
      DB_USERNAME: ${DB_USERNAME}
      DB_PASSWORD: ${DB_PASSWORD}

      FILESYSTEM_DISK: public
    volumes:
      - public_files:/var/www/html/public
      - upload_files:/var/www/html/storage/app/public
    depends_on:
      - db

  # ==========================================
  # 2. Web Server (Custom Nginx)
  # ==========================================
  web:
    build:
      context: .
      dockerfile: docker/nginx.Dockerfile
    restart: unless-stopped
    expose:
      - "80"
    volumes:
      - public_files:/var/www/html/public:ro
    depends_on:
      - app

  # ==========================================
  # 3. Database (Custom PostgreSQL)
  # ==========================================
  db:
    build:
      context: .
      dockerfile: docker/postgres.Dockerfile
    restart: unless-stopped
    environment:
      POSTGRES_DB: ${DB_DATABASE}
      POSTGRES_USER: ${DB_USERNAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  db_data:
  public_files:
  upload_files:
