<?php

namespace Modules\Objects;

use Src\Common\Dto\Object\AbstractComposite;
use Src\Common\Dto\Object\ImageObject;
use Src\Common\Dto\Object\StringObject;
use Src\Common\Dto\Object\TextObject;

class MainInfo extends AbstractComposite
{

    const TYPE = 'main-info';

    public function init()
    {
        $this->type = self::TYPE;
        $this->description = 'Main info';

        /** @var ImageObject */
        $image = $this->fieldsFactory->createObjectField(AbstractComposite::IMAGE_TYPE);
        $image->setDescriptionStr('Image');
        $image->setAR(400 / 500);
        $image->setPath('/files-browser');
        $this->fields['image'] = $image;

        /** @var StringObject */
        $h1 = $this->fieldsFactory->createObjectField(AbstractComposite::STRING_TYPE);
        $h1->setDescriptionStr('H1');
        $this->fields['h1'] = $h1;

        /** @var StringObject */
        $subtitle = $this->fieldsFactory->createObjectField(AbstractComposite::STRING_TYPE);
        $subtitle->setDescriptionStr('subtitle');
        $this->fields['subtitle'] = $subtitle;

        /** @var TextObject */
        $text = $this->fieldsFactory->createObjectField(AbstractComposite::HTML_TYPE);
        $text->setDescriptionStr('text');
        $this->fields['text'] = $text;
    }

    public function getField(string $field): ?string
    {
        /** @var ImageObject */
        $f = $this->fields[$field];
        return $f->getValue();
    }
}
