<?php

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

use InvalidArgumentException;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Enums\StavEmisnejKontrolyEnum;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaStavu;
use Seka\Portal\Modul\Statistiky\Tests\TestCase;

/**
 * Class PocetKontrolPodlaStavuTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Entities\Zaznam\ValueObjects
 */
class PocetKontrolPodlaStavuTest extends TestCase
{
    /**
     * @var int
     */
    private int $pocet;
    /**
     * @var \Seka\Portal\Modul\Statistiky\Entities\Zaznam\Enums\StavEmisnejKontrolyEnum
     */
    private StavEmisnejKontrolyEnum $stav;
    /**
     * @var \Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaStavu
     */
    private PocetKontrolPodlaStavu $pocetKontrolPodlaStavu;

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

        $this->stav = StavEmisnejKontrolyEnum::ARCHIV;
        $this->pocet = 15;

        $this->pocetKontrolPodlaStavu = new PocetKontrolPodlaStavu(
            $this->stav,
            $this->pocet
        );
    }

    /**
     *
     */
    public function testCreateInstance()
    {
        $pocetKontrolpodlaStavu = new PocetKontrolPodlaStavu(
            $this->stav,
            $this->pocet
        );

        self::assertInstanceOf(PocetKontrolPodlaStavu::class, $pocetKontrolpodlaStavu);
    }

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

    /**
     *
     */
    public function testStav()
    {
        self::assertInstanceOf(StavEmisnejKontrolyEnum::class, $this->pocetKontrolPodlaStavu->stav());
        self::assertEquals($this->stav, $this->pocetKontrolPodlaStavu->stav());
    }

    /**
     *
     */
    public function testEqualsStav()
    {
        $novaInstancia = clone $this->pocetKontrolPodlaStavu;
        self::assertTrue($this->pocetKontrolPodlaStavu->equalsStav($novaInstancia));
    }

    /**
     *
     */
    public function testNotEqualsStav()
    {
        $novaInstancia = new PocetKontrolPodlaStavu(StavEmisnejKontrolyEnum::STORNO, 1);
        self::assertFalse($this->pocetKontrolPodlaStavu->equalsStav($novaInstancia));
    }

    /**
     *
     */
    public function testNavysitPocetRovnakehoStavu()
    {
        $navysenie = new PocetKontrolPodlaStavu($this->stav, 7);
        $novaInstancia = $this->pocetKontrolPodlaStavu->navysitPocet($navysenie);
        self::assertInstanceOf(PocetKontrolPodlaStavu::class, $novaInstancia);
        self::assertFalse($novaInstancia->pocet() === $this->pocetKontrolPodlaStavu->pocet());
    }

    /**
     *
     */
    public function testNavysitPocetInehoStavu()
    {
        self::expectException(InvalidArgumentException::class);

        $navysenie = new PocetKontrolPodlaStavu(StavEmisnejKontrolyEnum::STORNO, 19);
        $this->pocetKontrolPodlaStavu->navysitPocet($navysenie);
    }

    /**
     *
     */
    public function testToArray()
    {
        self::assertIsArray($this->pocetKontrolPodlaStavu->toArray());
        self::assertArrayHasKey('stav', $this->pocetKontrolPodlaStavu->toArray());
        self::assertArrayHasKey('pocet', $this->pocetKontrolPodlaStavu->toArray());
        self::assertEquals($this->stav->value, $this->pocetKontrolPodlaStavu->toArray()['stav']);
        self::assertEquals($this->pocet, $this->pocetKontrolPodlaStavu->toArray()['pocet']);
    }

    /**
     *
     */
    public function testJsonSerialize()
    {
        self::assertJson($this->pocetKontrolPodlaStavu->jsonSerialize());
        self::assertJsonStringEqualsJsonString(
            '{"stav":"' . $this->stav->value . '","pocet":' . $this->pocet . '}',
            $this->pocetKontrolPodlaStavu->jsonSerialize()
        );
    }
}
