<?php

namespace KupShop\OrderingBundle\Attachment;

use KupShop\KupShopBundle\Config;
use KupShop\KupShopBundle\Email\EmailGroupTypeEnum;

class TermsAndConditionsAttachment extends BaseAttachment
{
    protected static $name = 'Obchodní podmínky';
    protected static $type = 'terms_and_conditions';
    protected static $group = EmailGroupTypeEnum::ORDER;

    public static function isAllowed()
    {
        if (!empty(\Settings::getDefault()->terms_and_conditions_file)) {
            return true;
        }

        return false;
    }

    public function getFilename(): string
    {
        $dbcfg = \Settings::getDefault();

        return $this->filename = basename($dbcfg->terms_and_conditions_file);
    }

    public function getContent()
    {
        $dbcfg = \Settings::getDefault();

        $path = '.'.$dbcfg->terms_and_conditions_file;
        if (isDevelopment() && !file_exists($path)) {
            $addr = Config::get()->getFromArray('Addr');
            $path = $addr['full_original'].rawurlencode(ltrim($dbcfg->terms_and_conditions_file, '/'));
        }

        return $path;
    }

    public function getAttachmentType()
    {
        return self::TYPE_PATH;
    }
}
