<?php

namespace ZenoChatbot\Framework\Support;

/**
 * Higher order proxy for when method
 */
class HigherOrderWhenProxy
{
    protected $collection;
    protected $condition;

    public function __construct($collection, $condition)
    {
        $this->collection = $collection;
        $this->condition = $condition;
    }

    public function __call($method, $parameters)
    {
        return $this->condition
            ? $this->collection->{$method}(...$parameters)
            : $this->collection;
    }
}
