<?php

declare(strict_types=1);

namespace Seka\Vzdelavanie\Dtos\Kniznica;

use Illuminate\Contracts\Support\Arrayable;
use Seka\Vzdelavanie\Models\Kniznica\Kategoria;

/**
 * Class KategoriaDTO
 *
 * @package Seka\Vzdelavanie\Dtos\Kniznica
 */
final class KategoriaDTO implements Arrayable
{
    /**
     * @var int
     */
    public int $id;

    /**
     * @var string
     */
    public string $hash_id;

    /**
     * @var string
     */
    public string $nazov;

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

    /**
     * @var string
     */
    public string $created_at;

    /**
     * @var string
     */
    public string $updated_at;

    /**
     * KategoriaDTO constructor.
     *
     * @param array $parameters
     */
    public function __construct(array $parameters = [])
    {
        $this->id = (int) ($parameters['id'] ?? 0);
        $this->hash_id = (string) ($parameters['hash_id'] ?? '');
        $this->nazov = (string) ($parameters['nazov'] ?? '');
        $this->obrazok = $parameters['obrazok'] ?? null;
        $this->created_at = (string) ($parameters['created_at'] ?? '');
        $this->updated_at = (string) ($parameters['updated_at'] ?? '');
    }

    /**
     * @param \Seka\Vzdelavanie\Models\Kniznica\Kategoria $model
     *
     * @return static
     */
    public static function fromModel(Kategoria $model): self
    {
        return new self($model->toArray());
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        return [
            'id' => $this->id,
            'hash_id' => $this->hash_id,
            'nazov' => $this->nazov,
            'obrazok' => $this->obrazok,
            'created_at' => $this->created_at,
            'updated_at' => $this->updated_at,
        ];
    }
}
