<?php

namespace CouponsPlus\App\Coupon\Tree\Data\Transformers;

use CouponsPlus\App\Coupon\Tree\Data\Transformers\Abilities\TransformationStrategy;

class OriginalDataOnExceptionStrategyDecorator implements TransformationStrategy
{
    private TransformationStrategy $strategy;

    public function __construct(TransformationStrategy $strategy)
    {
        $this->strategy = $strategy;
    }

    /**
     * @param \CouponsPlus\Original\Collections\Collection $transformers
     * @param object $data
     * @return object
     */
    public function execute($transformers, $data)
    {
        try {
            return $this->strategy->execute($transformers, $data);
        } catch (\RuntimeException $e) {
            // No matching transformer found, return original data unchanged
            return $data;
        }
    }
}
