<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Dtos\Kniznica;

use Elceka\Laravel\HashId\Facades\Hasher;
use Seka\Vzdelavanie\Dtos\DtoFromModelTrait;
use Spatie\DataTransferObject\DataTransferObject;

/**
 * Class SekciaDTO
 *
 * @package Seka\Vzdelavanie\Dtos\Kniznica
 */
class SekciaDTO extends DataTransferObject
{
    use DtoFromModelTrait;

    /**
     * @var int|null
     */
    public ?int $id;

    /**
     * @var string|null
     */
    public ?string $hash_id;

    /**
     * @var string|null
     */
    public ?string $nazov;

    /**
     * @var string|null
     */
    public ?string $obsah;

    /**
     * @var \Seka\Vzdelavanie\Dtos\Kniznica\UcebnicaDTO|null
     */
    public ?UcebnicaDTO $ucebnica;

    /**
     * @var \Seka\Vzdelavanie\Dtos\Kniznica\SekciaDTO|null
     */
    public ?self $parent;

    /**
     * @var \Seka\Vzdelavanie\Dtos\Kniznica\SekciaDTO[]|null
     */
    public ?array $children;

    /**
     * @var string|null
     */
    public ?string $link;

    /**
     * @var int|null
     */
    public ?int $parent_id;

    /**
     * @var int|null
     */
    public ?int $ucebnica_id;

    /**
     * SekciaDTO constructor.
     *
     * @param array $parameters
     *
     * @throws \Spatie\DataTransferObject\Exceptions\UnknownProperties
     * @throws \Spatie\DataTransferObject\Exceptions\ValidationException
     */
    public function __construct(array $parameters = [])
    {
        parent::__construct($parameters);

        $this->makeLink();
    }

    /**
     *
     */
    protected function makeLink(): void
    {
        $this->link = route(
            'vzdelavanie.kniznica.ucebnica.sekcia.show',
            [
                Hasher::encode($this->ucebnica_id),
                $this->hash_id,
            ]
        );
    }
}
