<?php

declare(strict_types=1);

namespace KupShop\BonusProgramBundle\Email;

use KupShop\KupShopBundle\Email\BaseEmail;
use Symfony\Component\Routing\Router;

class BonusExchangeCouponEmail extends BaseEmail
{
    protected static $name = 'Dárkový poukaz přes věrnostní program';
    protected static $type = 'BONUS_PROGRAM_COUPON';
    protected static $priority = 0;

    protected $subject = 'Posíláme Vám dárkový poukaz';
    protected $template = 'email/email_bonus_program_coupon.tpl';

    private ?int $couponId = null;

    public static function isAllowed()
    {
        return findModule(\Modules::BONUS_PROGRAM, \Modules::SUB_POINTS_EXCHANGE);
    }

    public function setCouponId(int $couponId): void
    {
        $this->couponId = $couponId;
    }

    public static function getPlaceholders()
    {
        $placeholders = [
            'ODKAZ_POUKAZ' => [
                'text' => 'Odkaz',
            ],
        ];

        return [self::$type => $placeholders] + (parent::getPlaceholders() ?? []);
    }

    public function replacePlaceholdersItem($placeholder)
    {
        if ($this->couponId) {
            switch ($placeholder) {
                case 'ODKAZ_POUKAZ':
                    return path('kupshop_bonusprogram_bonusprogramexchange_usercouponpdf', ['couponId' => $this->couponId], Router::ABSOLUTE_URL);
            }
        }

        return parent::replacePlaceholdersItem($placeholder);
    }
}
