<?php

namespace UserBundle\Entity\Notification\ThemeOption;

/**
 * Class ThemeOptionHeader
 * @package UserBundle\Entity\Notification\ThemeOption
 */
class ThemeOptionHeader implements \Serializable
{

    const DEFAULT_IMAGE = 'data:image/png;base64,[encoded data, 24260 characters]';

    /**
     * @var string
     */
    private $imageUrl;

    /**
     * @var string
     */
    private $logoLink;

    /**
     * @var string
     */
    private $title;

    /**
     * ThemeOptionHeader constructor.
     *
     * @param string $imageUrl Url to header image.
     * @param string $logoLink Header image link address.
     * @param string $title    Custom title in header.
     */
    public function __construct($imageUrl = self::DEFAULT_IMAGE, $logoLink = '', $title = '')
    {
        $this->imageUrl = trim($imageUrl);
        $this->logoLink = trim($logoLink);
        $this->title = trim($title);
    }

    /**
     * @return string
     */
    public function getImageUrl()
    {
        return $this->imageUrl;
    }

    /**
     * @return boolean
     */
    public function hasImageUrl()
    {
        return $this->imageUrl !== '';
    }

    /**
     * @param string $imageUrl Url to header image.
     *
     * @return $this
     */
    public function setImageUrl($imageUrl)
    {
        $this->imageUrl = $imageUrl;

        return $this;
    }

    /**
     * @return string
     */
    public function getLogoLink()
    {
        return $this->logoLink;
    }

    /**
     * @param string $logoLink Header image link address.
     *
     * @return $this
     */
    public function setLogoLink($logoLink)
    {
        $this->logoLink = $logoLink;

        return $this;
    }

    /**
     * @return string
     */
    public function getTitle()
    {
        return $this->title;
    }

    /**
     * @param string $title Custom title in header.
     *
     * @return $this
     */
    public function setTitle($title)
    {
        $this->title = $title;

        return $this;
    }

    /**
     * String representation of object.
     *
     * @return string the string representation of the object or null.
     */
    public function serialize()
    {
        return serialize([
            $this->imageUrl,
            $this->logoLink,
            $this->title,
        ]);
    }

    /**
     * Constructs the object
     *
     * @param string $serialized The string representation of the object.
     *
     * @return void
     */
    public function unserialize($serialized)
    {
        $data = unserialize($serialized);

        $this->imageUrl = $data[0];
        $this->logoLink = $data[1];
        $this->title = $data[2];
    }

    /**
     * @return array
     */
    public function toArray()
    {
        return [
            'imageUrl' => $this->imageUrl,
            'logoLink' => $this->logoLink,
            'title' => $this->title,
        ];
    }
}
