<?php
/** 
 * @package     VikRestaurants
 * @subpackage  core
 * @author      E4J s.r.l.
 * @copyright   Copyright (C) 2023 E4J s.r.l. All Rights Reserved.
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 * @link        https://vikwp.com
 */

namespace E4J\VikRestaurants\Cron\Traits;

// No direct access
defined('ABSPATH') or die('No script kiddies please!');

use E4J\VikRestaurants\Template\Taggable;

/**
 * Take-Away order template builder.
 * 
 * @since 1.10
 */
trait OrderNotificationTaggableBuilder
{
    /**
     * Bind the template with the values (tags) of the provided take-away order.
     * 
     * @param   Taggable           $template  The taggable template.
     * @param   \VREOrderTakeaway  $order     The object holding the take-away order details.
     * 
     * @return  void
     */
    protected function setupTemplate(Taggable $template, \VREOrderTakeaway $order)
    {
        // use default language if not specified
        $langtag = $order->langtag ? $order->langtag : \VikRestaurants::getDefaultLanguage();

        // inject generic order information, such as order ID and payment details
        $template->attachTemplateDecorator(new \E4J\VikRestaurants\Template\Decorators\OrderDecorator($order));

        // inject take-away order information
        $template->attachTemplateDecorator(new \E4J\VikRestaurants\Template\Decorators\TakeawayOrderDecorator($order, $langtag));

        // in case we have a mail template, we might inject further event arguments
        if (method_exists($template, 'addEventArgument'))
        {
            // required to properly use the conditional texts
            $template->addEventArgument($order);
        }
    }
}
