<?php

declare(strict_types=1);

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

use InvalidArgumentException;
use Seka\Portal\Modul\Statistiky\Tests\TestCase;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaObratuASubjektuFakturacie;

/**
 * Class PocetKontrolPodlaObratuASubjektuFakturacieTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Entities\Zaznam\ValueObjects
 */
class PocetKontrolPodlaObratuASubjektuFakturacieTest extends TestCase
{
    /**
     * @var \Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaObratuASubjektuFakturacie
     */
    private PocetKontrolPodlaObratuASubjektuFakturacie $obj;

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

    /**
     * @var float
     */
    private float $obrat;

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

    /**
     *
     */
    public function setUp(): void
    {
        parent::setUp();

        $this->pocet = 3;
        $this->obrat = 123.45;
        $this->nazovSubjektu = 'elceka IT';

        $this->obj = new PocetKontrolPodlaObratuASubjektuFakturacie($this->nazovSubjektu, $this->obrat, $this->pocet);
    }

    /**
     *
     */
    public function testInstancie()
    {
        $obj = new PocetKontrolPodlaObratuASubjektuFakturacie($this->nazovSubjektu, $this->obrat, $this->pocet);

        self::assertInstanceOf(PocetKontrolPodlaObratuASubjektuFakturacie::class, $obj);
    }

    /**
     *
     */
    public function testPocet()
    {
        self::assertEquals($this->pocet, $this->obj->pocet());
    }

    /**
     *
     */
    public function testObrat()
    {
        self::assertEquals($this->obrat, $this->obj->obrat());
    }

    /**
     *
     */
    public function testNazovSubjektu()
    {
        self::assertEquals($this->nazovSubjektu, $this->obj->nazovSubjektu());
    }

    /**
     *
     */
    public function testNavysitPocetAObrat()
    {
        $navysitObrat = 100.0;
        $navysitPocet = 2;

        $test = new PocetKontrolPodlaObratuASubjektuFakturacie($this->nazovSubjektu, $navysitObrat, $navysitPocet);
        $clone = (clone $this->obj)->navysitPocetAObrat($test);

        self::assertEquals($this->pocet + $navysitPocet, $clone->pocet());
        self::assertEquals($this->obrat + $navysitObrat, $clone->obrat());
    }

    /**
     *
     */
    public function testNavysitPocetAObratInymSubjektomFakturacie()
    {
        $navysitObrat = 100.0;
        $navysitPocet = 2;

        $test = new PocetKontrolPodlaObratuASubjektuFakturacie('test', $navysitObrat, $navysitPocet);

        self::expectException(InvalidArgumentException::class);

        $clone = (clone $this->obj)->navysitPocetAObrat($test);
    }

    /**
     *
     */
    public function testEqualsNazovSubjektu()
    {
        $clone = clone $this->obj;

        self::assertTrue($this->obj->equalsNazovSubjektu($clone));
    }

    /**
     *
     */
    public function testJsonSerialize()
    {
        self::assertJsonStringEqualsJsonString(
            '{"subjekt":"elceka IT","obrat":123.45,"pocet":3}',
            $this->obj->jsonSerialize()
        );
    }

    /**
     *
     */
    public function testToArray()
    {
        $arr = $this->obj->toArray();

        self::assertIsArray($arr);
        self::assertArrayHasKey('subjekt', $arr);
        self::assertArrayHasKey('obrat', $arr);
        self::assertArrayHasKey('pocet', $arr);
    }
}
