<?php

namespace KupShop\AdminBundle\Admin\Actions;

use KupShop\AdminBundle\Util\ActivityLog;
use KupShop\AdminBundle\Util\PrintCenter\PDF\StockInPDF;

class StockInPDFExportAction extends AbstractAction implements IAction
{
    /**
     * @var StockInPDF
     */
    protected $stockInPdf;

    public function getTypes(): array
    {
        return ['stockIn'];
    }

    public function getName(): string
    {
        return 'Exportovat do PDF';
    }

    public function execute(&$data, array $config, string $type): ActionResult
    {
        header('Content-Type: text/pdf');
        header('Content-Disposition: attachment; filename="Naskladneni_'.$this->getId().'.pdf"');

        addActivityLog(ActivityLog::SEVERITY_NOTICE, ActivityLog::TYPE_SECURITY, "Naskladnění: ruční export {$this->getId()} (PDF)");
        echo $this->stockInPdf->getPDF($this->getId());

        exit;
    }

    public function isEnabled()
    {
        return findModule(\Modules::STOCK_IN);
    }

    /**
     * @required
     */
    public function setStockInPdf(StockInPDF $stockInPdf): void
    {
        $this->stockInPdf = $stockInPdf;
    }

    public function hasDialog()
    {
        return false;
    }

    public function getColor()
    {
        return self::COLOR_SUCCESS;
    }
}
