<?php

declare(strict_types=1);

namespace KupShop\GTMBundle\Tests;

use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
use KupShop\DevelopmentBundle\Util\Tests\RequestSessionTrait;
use KupShop\GTMBundle\ServerSideGTMEvent\CartAddItemEvent;
use KupShop\GTMBundle\ServerSideGTMEvent\OrderComplete;
use KupShop\GTMBundle\ServerSideGTMEvent\OrderStornoEvent;
use KupShop\GTMBundle\ServerSideGTMEvent\ReservationCreatedEvent;
use KupShop\KupShopBundle\Util\System\AsyncQueue;
use KupShop\OrderDiscountBundle\Tests\OrderTestDiscountTrait;
use KupShop\ProductReservationBundle\Util\ProductReservationUtil;
use KupShop\ReservationBundle\Tests\ReservationTestTrait;
use KupShop\ReservationBundle\Util\ReservationUtil;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\EventDispatcher\Event;

class GTMServerSideTest extends \DatabaseTestCase
{
    use CartTestTrait;
    use RequestSessionTrait;
    use ReservationTestTrait;
    use GTMTestHelper;
    use OrderTestDiscountTrait;

    private const REQUEST_DEPENDANT_FIELDS = [
        'gtm_event_uid' => 'test_gtm_event_id',
        'User-Agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0',
        'referer' => 'http://www.kupshop.local/',
    ];

    protected function setUp(): void
    {
        parent::setUp();
        $this->prepareRequestStackSession();

        $this->setCartUserKey('123456');

        /** @var Request $req */
        $req = $this->get(RequestStack::class)->getMainRequest();
        $req->cookies->set('gtm_event_uid', self::REQUEST_DEPENDANT_FIELDS['gtm_event_uid']);

        $req->headers->set('User-Agent', self::REQUEST_DEPENDANT_FIELDS['User-Agent']);
        $req->headers->set('referer', self::REQUEST_DEPENDANT_FIELDS['referer']);

        $dbcfg = \Settings::getDefault();
        $dbcfg->analytics['google_tag_manager'] = [
            'ga4_measurement_id' => '69',
            'ga4_measurement_id_2' => '420',
            'ga4_measurement_id_3' => '1337',
        ];

        $this->loginUser(2);
        // setup settings for tests
        $dbcfg->reservations = [
            'merge_interval' => 20,
            'delivery_type' => 1,
        ];
        $this->reservationUtil = $this->get(ReservationUtil::class);
        $this->productReservationUtil = $this->get(ProductReservationUtil::class);
        $this->asyncQueue = $this->get(AsyncQueue::class);
    }

    public function testCartAddItemEvent()
    {
        $instance = $this->autowire(CartAddItemEventMock::class);
        $this->set(CartAddItemEvent::class, $instance);

        $this->createCart();
        $item = [
            'id_product' => 6,
            'id_variation' => 17,
            'pieces' => 1,
        ];
        $this->cart->addItem($item);

        $this->asyncQueue->handleAll();

        $expectedPayload = [
            'events' => [
                0 => [
                    'ga3_session_id' => '',
                    'name' => 'add_to_cart',
                    'user_id' => '123456',
                    'client_id' => '123456_noCookie',
                    'params' => [
                        'client_id' => '123456_noCookie',
                        'currency' => 'CZK',
                        'page_encoding' => 'UTF-8',
                        'domain' => 'www.kupshop.local',
                        'page_hostname' => 'www.kupshop.local',
                        'page_location' => 'https://www.kupshop.local',
                        'ga_session_id' => '',
                        'ga_session_id_2' => '',
                        'ga_session_id_3' => '',
                        'ip_override' => null,
                        'language' => 'cs',
                        'page_path' => self::REQUEST_DEPENDANT_FIELDS['referer'],
                        'page_title' => 'Salomon XR MISSION W - Demo Kupshop.cz',
                        'page_referrer' => self::REQUEST_DEPENDANT_FIELDS['referer'],
                        'user_agent' => self::REQUEST_DEPENDANT_FIELDS['User-Agent'],
                        'user_data' => [
                            'email_address' => 'wpj@wpj.cz',
                            'phone_number' => '+420775131478',
                            'address' => [
                                'first_name' => 'Wpj',
                                'last_name' => 'Wpj',
                                'street' => 'Fügnerova 1288',
                                'city' => 'Vrchlabí',
                                'region' => '',
                                'postal_code' => '54301',
                                'country' => '',
                            ],
                        ],
                        'value' => 3000.0,
                        'event_id' => self::REQUEST_DEPENDANT_FIELDS['gtm_event_uid'],
                        'user_id' => '123456',
                        'items' => [
                            0 => [
                                'default_item_name' => 'Salomon XR MISSION W',
                                'default_item_variant' => 'Velikost: 40',
                                'default_item_brand' => '',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Dámská obuv',
                                'item_id' => '6_17',
                                'product_code' => 'NO206',
                                'product_id' => 6,
                                'variation_code' => '',
                                'variation_id' => 17,
                                'ean' => null,
                                'item_name' => 'Salomon XR MISSION W',
                                'discount' => 0.0,
                                'item_brand' => '',
                                'item_variant' => 'Velikost: 40',
                                'price' => '3000',
                                'price_with_vat' => '3000',
                                'price_without_vat' => '2479.34',
                                'price_vat' => '520.66',
                                'vat_rate' => 21,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Dámská obuv',
                                'price_buy' => '0',
                                'quantity' => 1,
                                'index' => 1,
                                'soldOut' => 0.0,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/salomon-xr-mission-w_z6/',
                                'img_url' => 'https://www.kupshop.local/data/tmp/0/7/7_0.jpg?',
                            ],
                        ],
                    ],
                ],
            ],
        ];

        $this->assertEquals($expectedPayload, $instance->payload, 'Odeslaná data do GTM se liší od očekávaných!');
    }

    public function testOrderCompleteEvent(): void
    {
        $instance = $this->autowire(OrderCompleteMock::class);
        $this->set(OrderComplete::class, $instance);

        $this->loginUser(2);

        $this->createCart();
        $this->cart->createFromDB();

        $item = [
            'id_product' => 6,
            'id_variation' => 17,
            'pieces' => 1,
        ];

        $this->cart->addItem($item);

        $order = $this->cart->submitOrder();
        $this->assertInstanceOf(\Order::class, $order);
        $yearNum = date('y');
        $expectedPayload = [
            'user_id' => '123456',
            'client_id' => '123456_noCookie',
            'ga3_session_id' => '',
            'events' => [
                0 => [
                    'name' => 'purchase',
                    'params' => [
                        'user_id' => '123456',
                        'client_id' => '123456_noCookie',
                        'ga_session_id' => '',
                        'ga_session_id_2' => '',
                        'ga_session_id_3' => '',
                        'currency' => 'CZK',
                        'ip_override' => false,
                        'language' => 'cs',
                        'page_encoding' => 'UTF-8',
                        'page_hostname' => 'www.kupshop.local',
                        'page_location' => 'https://www.kupshop.local',
                        'page_path' => "/objednavka/{$order->id}/",
                        'page_title' => "Objednávka: 036{$yearNum}201",
                        'page_referrer' => false,
                        'user_agent' => false,
                        'user_data' => [
                            'email_address' => 'wpj@wpj.cz',
                            'phone_number' => '+420775131478',
                            'address' => [
                                'first_name' => 'Wpj',
                                'last_name' => 'Wpj',
                                'street' => 'Fügnerova 1288',
                                'city' => 'Vrchlabí',
                                'region' => '',
                                'postal_code' => '54301',
                                'country' => 'CZ',
                            ],
                            'id' => '2',
                            'groups' => [],
                            'lastOrderDate' => null,
                            'firstOrderDate' => null,
                            'countOrders' => null,
                        ],
                        'transaction_id' => "036{$yearNum}201",
                        'value' => '8999',
                        'vat' => '1562',
                        'delivery_type' => 'GLS',
                        'payment_type' => 'DefaultPayment',
                        'payment' => [
                            'type' => 'DefaultPayment',
                            'method' => [
                                'id' => null,
                            ],
                        ],
                        'items' => [
                            1 => [
                                'default_item_name' => 'Salomon XR MISSION W',
                                'default_item_variant' => 'Velikost: 40',
                                'default_item_brand' => '',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Dámská obuv',
                                'item_id' => '6_17',
                                'product_code' => 'NO206',
                                'product_id' => 6,
                                'variation_code' => '',
                                'variation_id' => 17,
                                'ean' => null,
                                'item_name' => 'Salomon XR MISSION W',
                                'discount' => 0.0,
                                'item_brand' => '',
                                'item_variant' => 'Velikost: 40',
                                'price' => '3000',
                                'price_with_vat' => '3000',
                                'price_without_vat' => '2479.34',
                                'price_vat' => '520.66',
                                'vat_rate' => 21.0,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Dámská obuv',
                                'price_buy' => '0',
                                'index' => 2,
                                'quantity' => '1',
                                'soldOut' => 0,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/salomon-xr-mission-w_z6/',
                            ],
                            0 => [
                                'default_item_name' => 'DeWALT DCD780C2 aku vrtačka',
                                'default_item_variant' => null,
                                'default_item_brand' => 'DeWALT',
                                'default_item_category' => 'Aku vrtačky',
                                'default_item_category2' => 'Aku vrtačky',
                                'item_id' => '9',
                                'product_code' => 'NL935',
                                'product_id' => '9',
                                'variation_code' => '',
                                'variation_id' => '',
                                'ean' => null,
                                'item_name' => 'DeWALT DCD780C2 aku vrtačka',
                                'discount' => 4.626,
                                'item_brand' => 'DeWALT',
                                'item_variant' => '',
                                'price' => '5999',
                                'price_with_vat' => '5999',
                                'price_without_vat' => '4957.85',
                                'price_vat' => '1041.15',
                                'vat_rate' => '21',
                                'item_category' => 'Aku vrtačky',
                                'item_category2' => 'Aku vrtačky',
                                'price_buy' => '0',
                                'index' => 1,
                                'quantity' => '1',
                                'description' => 'DeWALT DCD780C2 aku vrtačka',
                                'url' => 'https://www.kupshop.local/dewalt-dcd780c2-aku-vrtacka_z9/',
                            ],
                        ],
                        'shipping' => '0',
                        'domain' => 'www.kupshop.local',
                        'discounts' => [],
                        'coupon' => '',
                        'charges' => [],
                        'cjevent' => false,
                    ],
                ],
            ],
        ];

        $this->assertEquals($expectedPayload, $instance->payload, 'Odeslaná data do GTM se liší od očekávaných!');
    }

    public function provideCouponData(): \Generator
    {
        yield 'Without coupon' => [
            'coupons' => [],
            'expectedValue' => '8999',
            'expectedVat' => '1562',
            'expectedDiscounts' => [],
            'expectedCoupons' => '',
        ];

        yield 'With 1 coupon' => [
            'coupons' => ['TEST321'],
            'expectedValue' => '8099',
            'expectedVat' => '1406',
            'expectedDiscounts' => [
                [
                    'id' => 1,
                    'name' => 'Bar 10% (TEST321) (10%)',
                    'valueWithVat' => \Decimal::create('-899.90'),
                    'valueWithoutVat' => \Decimal::create('-743.72'),
                ],
            ],
            'expectedCoupons' => 'TEST321',
        ];

        yield 'With 2 coupons' => [
            'coupons' => ['TEST321', 'TEST3213'],
            'expectedValue' => '7199',
            'expectedVat' => '1249',
            'expectedDiscounts' => [
                [
                    'id' => 1,
                    'name' => 'Bar 10% (TEST321) (10%)',
                    'valueWithVat' => \Decimal::create('-899.90'),
                    'valueWithoutVat' => \Decimal::create('-743.72'),
                ], [
                    'id' => 1,
                    'name' => 'Bar 10% (TEST3213) (10%)',
                    'valueWithVat' => \Decimal::create('-899.90'),
                    'valueWithoutVat' => \Decimal::create('-743.72'),
                ],
            ],
            'expectedCoupons' => 'TEST321,TEST3213',
        ];

        yield 'With UPPERCASE coupons check' => [
            'coupons' => ['tEst321', 'test3213'],
            'expectedValue' => '7199',
            'expectedVat' => '1249',
            'expectedDiscounts' => [
                [
                    'id' => 1,
                    'name' => 'Bar 10% (TEST321) (10%)',
                    'valueWithVat' => \Decimal::create('-899.90'),
                    'valueWithoutVat' => \Decimal::create('-743.72'),
                ], [
                    'id' => 1,
                    'name' => 'Bar 10% (TEST3213) (10%)',
                    'valueWithVat' => \Decimal::create('-899.90'),
                    'valueWithoutVat' => \Decimal::create('-743.72'),
                ],
            ],
            'expectedCoupons' => 'TEST321,TEST3213',
        ];
    }

    /**
     * @dataProvider provideCouponData
     */
    public function testOrderCompleteEventCouponAndDiscounts(
        array $coupons,
        string $expectedValue,
        string $expectedVat,
        array $expectedDiscounts,
        string $expectedCoupons,
    ): void {
        $instance = $this->autowire(OrderCompleteMock::class);
        $this->set(OrderComplete::class, $instance);

        $this->loginUser(2);
        $this->activateDiscount([1]);
        $this->createCart();
        $item = [
            'id_product' => 6,
            'id_variation' => 17,
            'pieces' => 1,
        ];

        $this->cart->addItem($item);

        foreach ($coupons as $coupon) {
            $this->cart->addCoupon($coupon);
        }

        $this->cart->createFromDB();

        $order = $this->cart->submitOrder();
        $this->assertInstanceOf(\Order::class, $order);

        $yearNum = date('y');
        $expectedPayload = [
            'user_id' => '123456',
            'client_id' => '123456_noCookie',
            'ga3_session_id' => '',
            'events' => [
                0 => [
                    'name' => 'purchase',
                    'params' => [
                        'user_id' => '123456',
                        'client_id' => '123456_noCookie',
                        'ga_session_id' => '',
                        'ga_session_id_2' => '',
                        'ga_session_id_3' => '',
                        'currency' => 'CZK',
                        'ip_override' => false,
                        'language' => 'cs',
                        'page_encoding' => 'UTF-8',
                        'page_hostname' => 'www.kupshop.local',
                        'page_location' => 'https://www.kupshop.local',
                        'page_path' => "/objednavka/{$order->id}/",
                        'page_title' => "Objednávka: 036{$yearNum}201",
                        'page_referrer' => false,
                        'user_agent' => false,
                        'user_data' => [
                            'email_address' => 'wpj@wpj.cz',
                            'phone_number' => '+420775131478',
                            'address' => [
                                'first_name' => 'Wpj',
                                'last_name' => 'Wpj',
                                'street' => 'Fügnerova 1288',
                                'city' => 'Vrchlabí',
                                'region' => '',
                                'postal_code' => '54301',
                                'country' => 'CZ',
                            ],
                            'id' => '2',
                            'groups' => [],
                            'lastOrderDate' => null,
                            'firstOrderDate' => null,
                            'countOrders' => null,
                        ],
                        'transaction_id' => "036{$yearNum}201",
                        'value' => $expectedValue,
                        'vat' => $expectedVat,
                        'delivery_type' => 'GLS',
                        'payment_type' => 'DefaultPayment',
                        'payment' => [
                            'type' => 'DefaultPayment',
                            'method' => [
                                'id' => null,
                            ],
                        ],
                        'items' => [
                            1 => [
                                'default_item_name' => 'Salomon XR MISSION W',
                                'default_item_variant' => 'Velikost: 40',
                                'default_item_brand' => '',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Dámská obuv',
                                'item_id' => '6_17',
                                'product_code' => 'NO206',
                                'product_id' => 6,
                                'variation_code' => '',
                                'variation_id' => 17,
                                'ean' => null,
                                'item_name' => 'Salomon XR MISSION W',
                                'discount' => 0.0,
                                'item_brand' => '',
                                'item_variant' => 'Velikost: 40',
                                'price' => '3000',
                                'price_with_vat' => '3000',
                                'price_without_vat' => '2479.34',
                                'price_vat' => '520.66',
                                'vat_rate' => 21.0,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Dámská obuv',
                                'price_buy' => '0',
                                'index' => 2,
                                'quantity' => 1,
                                'soldOut' => 0,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/salomon-xr-mission-w_z6/',
                            ],
                            0 => [
                                'default_item_name' => 'DeWALT DCD780C2 aku vrtačka',
                                'default_item_variant' => null,
                                'default_item_brand' => 'DeWALT',
                                'default_item_category' => 'Aku vrtačky',
                                'default_item_category2' => 'Aku vrtačky',
                                'item_id' => '9',
                                'product_code' => 'NL935',
                                'product_id' => '9',
                                'variation_code' => '',
                                'variation_id' => '',
                                'ean' => null,
                                'item_name' => 'DeWALT DCD780C2 aku vrtačka',
                                'discount' => 4.626,
                                'item_brand' => 'DeWALT',
                                'item_variant' => '',
                                'price' => '5999',
                                'price_with_vat' => '5999',
                                'price_without_vat' => '4957.85',
                                'price_vat' => '1041.15',
                                'vat_rate' => '21',
                                'item_category' => 'Aku vrtačky',
                                'item_category2' => 'Aku vrtačky',
                                'price_buy' => '0',
                                'index' => 1,
                                'quantity' => '1',
                                'description' => 'DeWALT DCD780C2 aku vrtačka',
                                'url' => 'https://www.kupshop.local/dewalt-dcd780c2-aku-vrtacka_z9/',
                            ],
                        ],
                        'shipping' => '0',
                        'domain' => 'www.kupshop.local',
                        'discounts' => $expectedDiscounts,
                        'coupon' => $expectedCoupons,
                        'charges' => [],
                        'cjevent' => false,
                    ],
                ],
            ],
        ];

        $this->assertEquals($expectedPayload, $instance->payload, 'Odeslaná data do GTM se liší od očekávaných!');
    }

    public function testOrderStornoEvent(): void
    {
        $instance = $this->autowire(OrderStornoMock::class);
        $this->set(OrderStornoEvent::class, $instance);

        $order = new \Order();
        $order->createFromDB(9999);
        $order->storno();

        $expectedPayload = [
            'events' => [
                0 => [
                    'name' => 'refund',
                    'params' => [
                        'currency' => 'CZK',
                        'transaction_id' => '9999',
                        'value' => '303',
                        'tax' => '53',
                        'shipping' => '138',
                        'delivery_type' => 'GLS',
                        'payment_type' => 'ThePay',
                        'refund_type' => 'storno',
                        'items' => [
                            0 => [
                                'default_item_name' => 'Salomon XR MISSION W',
                                'default_item_variant' => 'Velikost: 40',
                                'default_item_brand' => '',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Dámská obuv',
                                'item_id' => '6_17',
                                'product_code' => 'NO206',
                                'product_id' => 6,
                                'variation_code' => '',
                                'variation_id' => 17,
                                'ean' => null,
                                'item_name' => 'Salomon XR MISSION W',
                                'discount' => 0.0,
                                'item_brand' => '',
                                'item_variant' => 'Velikost: 40',
                                'price' => '140',
                                'price_with_vat' => '140',
                                'price_without_vat' => '115.7',
                                'price_vat' => '24.3',
                                'vat_rate' => 21.0,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Dámská obuv',
                                'price_buy' => '0',
                                'index' => 1,
                                'quantity' => 1,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/salomon-xr-mission-w_z6/',
                            ],
                            1 => [
                                'default_item_name' => 'Adidas Mundial Goal Dalsi Test Velmi Dlouheho Produktoveho Nazvu',
                                'default_item_variant' => null,
                                'default_item_brand' => 'Adidas',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Pánská obuv',
                                'item_id' => '2',
                                'product_code' => 'JQ671',
                                'product_id' => 2,
                                'variation_code' => '',
                                'variation_id' => '',
                                'ean' => 1002,
                                'item_name' => 'Adidas Mundial Goal Dalsi Test Velmi Dlouheho Produktoveho Nazvu',
                                'discount' => 10.0,
                                'item_brand' => 'Adidas',
                                'item_variant' => '',
                                'price' => '25',
                                'price_with_vat' => '25',
                                'price_without_vat' => '20.66',
                                'price_vat' => '4.34',
                                'vat_rate' => 21.0,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Pánská obuv',
                                'price_buy' => '0',
                                'index' => 2,
                                'quantity' => 1,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/adidas-mundial-goal-dalsi-test-velmi-dlouheho-produktoveho-nazvu_z2/',
                            ],
                        ],
                        'coupon' => '',
                        'user_data' => [
                            'email_address' => 'montyklima@seznam.cz',
                            'phone_number' => '+420703429773',
                            'address' => [
                                'first_name' => 'Martin',
                                'last_name' => 'klima',
                                'street' => 'Častrov 54',
                                'city' => 'Častrov',
                                'region' => '',
                                'postal_code' => '39463',
                                'country' => 'CZ',
                            ],
                            'sha_email' => '015c5b6ca18abbcf610861062ec0f9a78fdb55085ab6024dc7525c5829555e75',
                            'id' => '2',
                            'groups' => [],
                            'lastOrderDate' => null,
                            'firstOrderDate' => null,
                            'countOrders' => null,
                        ],
                        'cjevent' => false,
                    ],
                ],
            ],
        ];

        $this->assertEqualsWithDelta($expectedPayload, $instance->payload, 0.001, 'Odeslaná data do GTM se liší od očekávaných!');
    }

    public function testReservationCreatedEvent()
    {
        $instance = $this->autowire(ReservationCreatedMock::class);
        $this->set(ReservationCreatedEvent::class, $instance);

        $reservation = $this->createTestReservation(6, 17, false);

        $expectedPayload = [
            'user_id' => '123456',
            'client_id' => '123456_noCookie',
            'ga3_session_id' => '',
            'events' => [
                0 => [
                    'name' => 'purchase',
                    'params' => [
                        'user_id' => '123456',
                        'client_id' => '123456_noCookie',
                        'ga_session_id' => '',
                        'ga_session_id_2' => '',
                        'ga_session_id_3' => '',
                        'currency' => 'CZK',
                        'ip_override' => null,
                        'language' => 'cs',
                        'page_encoding' => 'UTF-8',
                        'page_hostname' => 'www.kupshop.local',
                        'page_location' => 'https://www.kupshop.local',
                        'page_path' => '/salomon-xr-mission-w_z6/',
                        'page_title' => 'Salomon XR MISSION W',
                        'page_referrer' => null,
                        'user_agent' => null,
                        'user_data' => [
                            'email_address' => 'test@wpj.cz',
                            'phone_number' => '+420123456789',
                            'address' => [
                                'first_name' => 'Wpj',
                                'last_name' => 'Wpj',
                                'street' => null,
                                'city' => null,
                                'region' => null,
                                'postal_code' => null,
                                'country' => null,
                            ],
                        ],
                        'transaction_id' => 'RES'.$reservation->id,
                        'value' => '3000',
                        'vat' => '521',
                        'delivery_type' => 'Osobní odběr',
                        'payment_type' => 'Hotově',
                        'items' => [
                            0 => [
                                'default_item_name' => 'Salomon XR MISSION W',
                                'default_item_variant' => 'Velikost: 40',
                                'default_item_brand' => '',
                                'default_item_category' => 'Obuv',
                                'default_item_category2' => 'Dámská obuv',
                                'item_id' => '6_17',
                                'product_code' => 'NO206',
                                'product_id' => 6,
                                'variation_code' => '',
                                'variation_id' => 17,
                                'ean' => null,
                                'item_name' => 'Salomon XR MISSION W',
                                'discount' => 0,
                                'item_brand' => '',
                                'item_variant' => 'Velikost: 40',
                                'price' => '3000',
                                'price_with_vat' => '3000',
                                'price_without_vat' => '2479.34',
                                'price_vat' => '520.66',
                                'vat_rate' => 21.0,
                                'item_category' => 'Obuv',
                                'item_category2' => 'Dámská obuv',
                                'price_buy' => '0',
                                'index' => 1,
                                'quantity' => 1,
                                'description' => 'Lorem ipsum dolor sit amet',
                                'url' => 'https://www.kupshop.local/salomon-xr-mission-w_z6/',
                            ],
                        ],
                        'shipping' => \DecimalConstants::zero(),
                        'shaEmail' => '63b2911182da44aa29a8d2c0422645c82eefeacc2ff5a65c20a0c6923a867809',
                        'domain' => 'www.kupshop.local',
                    ],
                ],
            ],
        ];

        $this->assertEqualsWithDelta($expectedPayload, $instance->payload, 0.001, 'Odeslaná data do GTM se liší od očekávaných!');
    }

    public function getDataSet(): \IteratorAggregate
    {
        return $this->getJsonDataSetFromFile();
    }
}

class CartAddItemEventMock extends CartAddItemEvent
{
    public ?array $payload = null;

    public function start(Event $event)
    {
        $this->payload = $this->getPayload($event);
    }
}

class OrderCompleteMock extends OrderComplete
{
    public ?array $payload = null;

    public function start(Event $event)
    {
        $this->payload = $this->getPayload($event);
    }
}
class ReservationCreatedMock extends ReservationCreatedEvent
{
    public ?array $payload = null;

    public function start(Event $event)
    {
        $this->payload = $this->getPayload($event);
    }
}

class OrderStornoMock extends OrderStornoEvent
{
    public ?array $payload = null;

    public function start(Event $event)
    {
        $this->payload = $this->getPayload($event);
    }
}
