<?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\Enums\DruhPalivaEnum;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\Enums\EmisnySystemEnum;
use Seka\Portal\Modul\Statistiky\Entities\Zaznam\ValueObjects\PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla;

/**
 * Class PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaTest
 *
 * @package Seka\Portal\Modul\Statistiky\Tests\Unit\Entities\Zaznam\ValueObjects
 */
class PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidlaTest extends TestCase
{
    /**
     *
     */
    public function testCreateInstance()
    {
        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::BKAT(),
            10
        );

        self::assertInstanceOf(PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla::class, $object);
    }

    /**
     *
     */
    public function testEmisnySystem()
    {
        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::RKAT_OBD(),
            10
        );

        self::assertTrue($object->emisnySystem()->equals(EmisnySystemEnum::RKAT_OBD()));
    }

    /**
     *
     */
    public function testDruhPaliva()
    {
        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::RKAT(),
            10
        );

        self::assertTrue($object->druhPaliva()->equals(DruhPalivaEnum::B()));
    }

    /**
     *
     */
    public function testPocet()
    {
        $pocet = 183;

        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::BKAT(),
            $pocet
        );

        self::assertIsInt($object->pocet());
        self::assertTrue($pocet === $object->pocet());
    }

    /**
     *
     */
    public function testEqualsDruhPalivaAEmisnehoSystemu()
    {
        $objectDBKAT1 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::BKAT(),
            99
        );

        $objectDBKAT2 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::BKAT(),
            1
        );

        $objectDNKAT = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::NKAT(),
            1
        );

        $objectBBKAT = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::BKAT(),
            1
        );

        self::assertFalse($objectDBKAT1->equalsDruhPalivaAEmisnehoSystemu($objectBBKAT));
        self::assertFalse($objectDBKAT1->equalsDruhPalivaAEmisnehoSystemu($objectDNKAT));
        self::assertTrue($objectDBKAT1->equalsDruhPalivaAEmisnehoSystemu($objectDBKAT2));
    }

    /**
     *
     */
    public function testNavysitPocet()
    {
        $pocet1 = 79;
        $pocet2 = 123;

        $object1 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::RKAT_OBD(),
            $pocet1
        );

        $object2 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::RKAT_OBD(),
            $pocet2
        );

        $object3 = $object1->navysitPocet($object2);

        self::assertIsInt($object3->pocet());
        self::assertSame($pocet1 + $pocet2, $object3->pocet());
    }

    /**
     *
     */
    public function testNavysitPocetPoctomInehoDruhuPalivaAEmisnehoSystemu()
    {
        $object1 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::B(),
            EmisnySystemEnum::BKAT(),
            1
        );

        $object2 = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::BKAT(),
            2
        );

        $this->expectException(InvalidArgumentException::class);
        $object1->navysitPocet($object2);
    }

    /**
     *
     */
    public function testToArray()
    {
        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::NKAT(),
            10
        );

        $array = $object->toArray();

        self::assertIsArray($array);

        self::assertArrayHasKey('druh_paliva', $array);
        self::assertArrayHasKey('emisny_system', $array);
        self::assertArrayHasKey('pocet', $array);
    }

    /**
     *
     */
    public function testJsonSerialize()
    {
        $object = new PocetKontrolPodlaDruhuPalivaAEmisnehoSystemuVozidla(
            DruhPalivaEnum::D(),
            EmisnySystemEnum::NKAT_OBD(),
            79
        );

        $jsonString = $object->jsonSerialize();

        self::assertJson($jsonString);
        self::assertJsonStringEqualsJsonString(
            '{"druh_paliva":"D","emisny_system":"NKAT_OBD","pocet":79}',
            $jsonString
        );
    }
}
