<?php

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

use Alsendo\AlsendoWrapper\Api\Ecolet\Model\Order\EcoletOrderResponse;
use Alsendo\AlsendoWrapper\Api\Ecolet\Model\Order\EcoletOrderValuation;
use Alsendo\AlsendoWrapper\Json;
use PHPUnit\Framework\TestCase;

class EcoletOrderGetResponseTest extends TestCase
{
    public function testOrderResponseFromJson()
    {
        $json = '{
  "data": {
    "id": 1,
    "service": {
      "slug": "dpd_standard",
      "full_name": "DPD Standard",
      "courier_slug": "dpd",
      "courier_name": "DPD"
    },
    "shipment_type": "primary",
    "primary_order_awb": null,
    "sender": {
      "id": 1,
      "name": "Test Company",
      "locality_id": 323,
      "country": "ro",
      "county": "Bucuresti",
      "locality": "Bucuresti",
      "postal_code": "011318",
      "has_streets": true,
      "street_name": "Bucuresti-Ploiesti",
      "street_number": "172-176",
      "block": "1",
      "entrance": "A2",
      "floor": "1",
      "flat": "A3a",
      "contact_person": "Test Test",
      "email": "test@ecolet.ro",
      "phone": "0214824089",
      "map_point_id": null,
      "map_point_name": null,
      "updated_at": null,
      "created_at": "2025-04-10T07:30:48.679Z"
    },
    "receiver": {
      "id": 1,
      "name": "Test Company",
      "locality_id": 323,
      "country": "ro",
      "county": "Bucuresti",
      "locality": "Bucuresti",
      "postal_code": "011318",
      "has_streets": true,
      "street_name": "Bucuresti-Ploiesti",
      "street_number": "172-176",
      "block": "1",
      "entrance": "A2",
      "floor": "1",
      "flat": "A3a",
      "contact_person": "Test Test",
      "email": "test@ecolet.ro",
      "phone": "0214824089",
      "map_point_id": null,
      "map_point_name": null,
      "updated_at": null,
      "created_at": "2025-04-10T07:30:48.680Z"
    },
    "awb": "80438360579",
    "waybill_extension": "pdf",
    "waybill_has_been_downloaded": false,
    "status": "new",
    "type": "package",
    "amount": 1,
    "price": 16.28,
    "content": "books",
    "shape": "standard",
    "weight": 1,
    "length": 10,
    "width": 15,
    "height": 10,
    "declared_value": null,
    "cod": 500,
    "cod_received_at": null,
    "cod_returned_at": null,
    "observations": null,
    "pickup_date": "2022-01-21",
    "pickup_hour": "13:00",
    "fees": [
      {
        "type": "base",
        "value": "15.50"
      }
    ],
    "vat": 19,
    "statuses": [
      {
        "name": "new",
        "real_name": "new",
        "created_at": "2025-04-10T07:30:48.680Z"
      }
    ],
    "updated_at": "2025-04-10T07:30:48.680Z",
    "created_at": "2025-04-10T07:30:48.680Z"
  }
}';
        $decodedJson = json_decode($json, true, 12, JSON_THROW_ON_ERROR);

        $orderToSend = Json::mapArrayToObject($decodedJson['data'], EcoletOrderResponse::class);

        $this->assertInstanceOf(EcoletOrderResponse::class, $orderToSend);
    }
}