<?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;

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

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

        // inject restaurant reservation information
        $template->attachTemplateDecorator(new \E4J\VikRestaurants\Template\Decorators\RestaurantReservationDecorator($reservation, $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($reservation);
        }
    }
}
