<?php

declare(strict_types=1);

namespace KupShop\GraphQLBundle\ApiShared\Types\Content;

use KupShop\ContentBundle\Util\Block;
use TheCodingMachine\GraphQLite\Annotations\Autowire;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;

#[Type]
class EditableArea
{
    public function __construct(private array $block)
    {
    }

    #[Field(description: 'ID.')]
    public function getId(): int
    {
        return $this->block['id'];
    }

    #[Field(description: 'Pozice.')]
    public function getPosition(): int
    {
        return $this->block['position'];
    }

    #[Field(description: 'Název.')]
    public function getName(): ?string
    {
        return !empty($this->block['name']) ? $this->block['name'] : null;
    }

    #[Field(description: 'Obsah ve formátu HTML. Vyrenderovaný z JSON dat z pole data.')]
    public function getContent(): string
    {
        return $this->block['content'] ?: '';
    }

    #[Field(description: 'JSON data obsahu.')]
    public function getData(): string
    {
        return $this->block['json_content'] ?: '[]';
    }

    /**
     * @Autowire(for="$blockUtil")
     */
    #[Field(description: 'Přenosná JSON data obsahu. Např. místo ID fotek se v datech nachází URL adresa vedoucí k fotce.')]
    public function getDataPortable(Block $blockUtil): string
    {
        return $blockUtil->getBlockPortableData($this->block);
    }
}
