<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolSObratom;

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolSObratom;
use Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\EChartSourceItemContract;

/**
 * Class PocetKontrolSObratomEChartSourceItem
 *
 * @package Seka\Portal\Modul\Statistiky\Repositories\Eloquent\Transformers\Summary\ECharts\Technik\PocetKontrolSObratom
 */
final class PocetKontrolSObratomEChartSourceItem implements EChartSourceItemContract, Arrayable, Jsonable, JsonSerializable
{
    /**
     * @var float
     */
    private float $obrat = 0;

    /**
     * @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\PocetKontrolSObratom $pocetKontrolSObratom
     *
     * @return $this
     */
    public function add(PocetKontrolSObratom $pocetKontrolSObratom): self
    {
        $this->obrat = $pocetKontrolSObratom->obrat();
        $this->spolu = $pocetKontrolSObratom->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,
            'obrat' => $this->obrat,
            'spolu' => $this->spolu,
        ];
    }

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