<?php

declare(strict_types=1);

namespace Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects;

/**
 * Class PocetKontrolSObratom
 *
 * @package Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects
 */
final class PocetKontrolSObratom implements PocetKontrol
{
    /**
     * @var float
     */
    private float $obrat;

    /**
     * @var int
     */
    private int $pocet;

    /**
     * PocetKontrolSObratom constructor.
     *
     * @param float  $obrat
     * @param int    $pocet
     */
    public function __construct(float $obrat, int $pocet)
    {
        $this->obrat = $obrat;
        $this->pocet = $pocet;
    }

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

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

    /**
     * @param \Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolSObratom $zdroj
     *
     * @return $this
     */
    public function navysitPocetAObrat(PocetKontrolSObratom $zdroj): self
    {
        return new self(
            (float) $this->obrat + $zdroj->obrat,
            (int) $this->pocet + $zdroj->pocet
        );
    }

    /**
     * @return array
     */
    public function toArray(): array
    {
        return [
            'obrat' => $this->obrat,
            'pocet' => $this->pocet,
        ];
    }

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