<?php

namespace KupShop\OrderingBundle\Attachment;

use KupShop\KupShopBundle\Email\EmailGroupTypeEnum;
use KupShop\OrderingBundle\Util\Invoice\PdfGenerator;
use KupShop\ReturnsBundle\Entity\ReturnEntity;

class ReplacementPDFAttachment extends BaseAttachment
{
    protected static $name = 'Opravný daňový doklad';
    protected static $type = 'order_replacement';
    protected static $group = EmailGroupTypeEnum::ORDER;

    protected $filename = 'OpravnyDanovyDoklad_{KOD}.pdf';
    protected $template = 'invoiceVratka';
    /** @var ReturnEntity */
    protected $return;

    private $pdfGenerator;

    public function __construct(PdfGenerator $pdfGenerator)
    {
        $this->pdfGenerator = $pdfGenerator;
    }

    public static function isAllowed()
    {
        return findModule(\Modules::REPLACEMENT) || findModule(\Modules::RETURNS);
    }

    public function getFilename(): string
    {
        return $this->order->replacePlaceholders(translate_shop('replacement_filename', 'attachments'));
    }

    public function getContent()
    {
        return $this->pdfGenerator->setTemplate($this->getTemplate())->getInvoicePDFContent($this->order->id);
    }

    public function setReturn(ReturnEntity $return)
    {
        $this->return = $return;
    }
}
