<?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\Mail\Decorators;

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

use E4J\VikRestaurants\Mail\Mail;
use E4J\VikRestaurants\Mail\MailDecorator;

/**
 * Extracts the customer e-mail from the provided order and sets it as recipient.
 *
 * @since 1.10
 */
final class RecipientCustomerMailDecorator implements MailDecorator
{
    /** @var \VREOrderWrapper */
    private $order;

    /**
     * Class constructor.
     * 
     * @param  \VREOrderWrapper  $order  The order details.
     */
    public function __construct(\VREOrderWrapper $order)
    {
        $this->order = $order;
    }

    /**
     * @inheritDoc
     */
    public function build(Mail $mail)
    {
        if ($this->order->purchaser_mail)
        {
            // set customer as recipient
            $mail->addRecipient($this->order->purchaser_mail);
        }
    }
}
