<?php

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

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

class TreeNodeBranchTransformer implements DataTransformer
{
    protected DataTransformer $branchTransformer;

    public function __construct(DataTransformer $branchTransformer)
    {
        $this->branchTransformer = $branchTransformer;
    }

    /**
     * @param object $data Raw tree node data
     * @return object Tree node branch data a format compatible with the Offers Engine
     */
    public function transform($data) : object
    {
        return (object) array_merge((array) $data, [
            'branch' => $this->branchTransformer->transform($data->branch),
        ]);
    }
}