<?php

namespace KupShop\OrderingBundle\Attachment;

use KupShop\KupShopBundle\Email\EmailGroupTypeEnum;
use KupShop\OrderingBundle\Exception\MethodNotImplementedException;

class BaseAttachment implements AttachmentInterface
{
    public const TYPE_TEXT = 'text';
    public const TYPE_PATH = 'path';

    protected static $name;
    protected static $type;
    protected static $group = EmailGroupTypeEnum::ORDER;
    protected static $priority = 0;

    protected $filename;
    protected $template;

    /** @var \Order */
    protected $order;

    public static function getName(): string
    {
        return static::$name;
    }

    public static function getType(): string
    {
        return static::$type;
    }

    public static function getGroup(): string
    {
        return static::$group->value;
    }

    public static function getPriority()
    {
        return static::$priority;
    }

    public static function isAllowed()
    {
        return true;
    }

    public function setOrder(\Order $order)
    {
        $this->order = $order;
    }

    public function getTemplate()
    {
        return $this->template;
    }

    public function getMimeType()
    {
        return 'application/pdf';
    }

    public function getFilename(): string
    {
        if (!$this->filename) {
            throw new \InvalidArgumentException(sprintf('%s::%s cannot be null!', get_class($this), '$filename'));
        }

        return $this->order->replacePlaceholders($this->filename);
    }

    public function getContent()
    {
        throw new MethodNotImplementedException(sprintf('You have not implemented method %s::%s()!', get_class($this), 'getContent'));
    }

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

    public function getAttachment(): array
    {
        return [
            'filename' => $this->getFilename(),
            'attachment' => $this->getContent(),
            'attachment_type' => $this->getAttachmentType(),
            'mime_type' => $this->getMimeType(),
        ];
    }
}
