<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\Technik\PocetKontrolPodlaKategorieVozidla;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaKategorieVozidla;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\DataTableRowContract;

/**
 * Class PocetKontrolPodlaKategorieVozidlaDataTableRow
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\DataTables\Technik\PocetKontrolPodlaKategorieVozidla
 */
final class PocetKontrolPodlaKategorieVozidlaDataTableRow implements DataTableRowContract, Arrayable, Jsonable, JsonSerializable
{
    /**
     * @var array
     */
    private array $kategoriaVozidlaPocet = [];

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

    /**
     * @var int
     */
    private int $spolu = 0;

    /**
     * @param string $technik
     */
    public function __construct(string $technik)
    {
        $this->technik = $technik;
    }

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaKategorieVozidla $pocetKontrolPodlaKategorieVozidla
     *
     * @return $this
     */
    public function add(PocetKontrolPodlaKategorieVozidla $pocetKontrolPodlaKategorieVozidla): self
    {
        $this->kategoriaVozidlaPocet[$pocetKontrolPodlaKategorieVozidla->kategoria()] = $pocetKontrolPodlaKategorieVozidla->pocet();
        $this->spolu += $pocetKontrolPodlaKategorieVozidla->pocet();

        return $this;
    }

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

    /**
     * @param int $options
     *
     * @return string
     */
    public function toJson($options = 0): string
    {
        return json_encode($this->toArray(), $options);
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        return [
            'label' => $this->technik,
            'data' => [
                'kategoria' => $this->kategoriaVozidlaPocet,
                'spolu' => $this->spolu,
            ],
        ];
    }

    /**
     * @return array
     */
    public function jsonSerialize(): array
    {
        return $this->toArray();
    }
}
