<?php

namespace Alsendo\AlsendoWrapper\Tests\Unit\Api\Apaczka;

use Alsendo\AlsendoWrapper\Api\Apaczka\Model\Order\Valuation\ApaczkaOrderValuation;
use Alsendo\AlsendoWrapper\Api\Apaczka\Wrapper\ApaczkaOrderValuationWrapper;
use PHPUnit\Framework\TestCase;

class ApaczkaOrderValuationTest extends TestCase
{
    /**
     * Tests if the order valuation is correctly parsed from JSON.
     *
     * @covers \Alsendo\AlsendoWrapper\Api\Apaczka\ApiApaczkaClient::getOrderValuation
     */
    public function testOrderValuationFromJson()
    {
        $json = '{
    "price_table": {
      "82": {
        "price": 1868,
        "price_gross": 2298
      }
    }
  }';
        $decodedJson = json_decode($json, true);
        $orderValuation = [];
        foreach ($decodedJson['price_table'] as $serviceId => $priceTableItem) {

            $orderValuation[$serviceId] = ApaczkaOrderValuationWrapper::wrap($serviceId, $priceTableItem);
        }
        $this->assertIsArray($orderValuation);
        $this->assertInstanceOf(ApaczkaOrderValuation::class, reset($orderValuation));
    }
}