<?php

namespace CouponsPlus\App\Coupon\Tree\Testable;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\Original\Environment\Env;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeData;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeDataFilterableSet;
use CouponsPlus\App\Coupon\Tree\Abilities\NodeDatas;
use Error;

class EmptySetOnExceptionInProductionSetFiltererFromNodeData extends SetFiltererFromNodeDataDecorator implements NodeDataFilterableSet
{
    public function filterSet(ItemsSet $itemsSet, NodeData $nodeData, NodeDatas $relatedNodeDatas): ItemsSet
    {
        try {
            (object) $filteredSet = $this->setFilterer->filterSet($itemsSet, $nodeData, $relatedNodeDatas);

            return $filteredSet;
        } catch (Error $exception) {
            $isProduction = Env::settings()->environment === 'production';

            if (!$isProduction) {
                throw $exception;
            }

            return new ItemsSet([]);
        }
    }
}