<?php

declare(strict_types=1);

namespace External\HannahBundle\EmailRegister;

use KupShop\KupShopBundle\Email\EmailInterface;
use KupShop\KupShopBundle\EmailRegister\EmailRegisterInterface;
use KupShop\KupShopBundle\Util\Database\QueryHint;
use KupShop\ReturnsBundle\Email\ReturnEmail;

class ReturnEmailRegister implements EmailRegisterInterface
{
    public function applyPlaceholders(EmailInterface $email): void
    {
        if (!($email instanceof ReturnEmail)) {
            return;
        }

        $return = $email->getReturn();

        $email->addPlaceholder('ODKAZ_DOBROPIS', function () use ($return) {
            $data = QueryHint::withRouteToMaster(fn () => $return->getCustomData());

            return $data['sapCreditNoteUrl'] ?? '';
        }, 'Odkaz na dobropis');
    }
}
