<?php

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

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

class EcoletOrderSendResponseTest extends TestCase
{
    public function testCreateOrderResponseFromJson()
    {
        $json = '{
  "order_to_send" : {
    "id" : 2721331,
    "status" : "ordered",
    "error" : null,
    "order_id" : 2223205,
    "order" : {
      "data" : {
        "sender" : {
          "name" : "Test Company",
          "postal_code" : "011318",
          "contact_person" : "Test Test",
          "email" : "test@ecolet.ro",
          "phone" : "0214824089",
          "country" : "ro",
          "locality_id" : 13751,
          "street_name" : "Bucuresti-Ploiesti",
          "street_number" : "172-176",
          "block" : "1",
          "entrance" : "A2",
          "floor" : "1",
          "flat" : "A3a",
          "has_map_point" : false,
          "map_point_id" : null,
          "county" : "Bucuresti",
          "locality" : "Bucuresti"
        },
        "receiver" : {
          "name" : "Test Company",
          "postal_code" : "011318",
          "contact_person" : "Test Test",
          "email" : "test@ecolet.ro",
          "phone" : "0214824089",
          "country" : "ro",
          "locality_id" : 13751,
          "street_name" : "Bucuresti-Ploiesti",
          "street_number" : "172-176",
          "block" : "1",
          "entrance" : "A2",
          "floor" : "1",
          "flat" : "A3a",
          "has_map_point" : false,
          "map_point_id" : null,
          "county" : "Bucuresti",
          "locality" : "Bucuresti"
        },
        "parcel" : {
          "type" : "package",
          "shape" : "standard",
          "amount" : null,
          "observations" : null
        },
        "parcels" : [ {
          "weight" : 10,
          "dimensions" : {
            "length" : 10,
            "width" : 10,
            "height" : 10
          },
          "declared_value" : null,
          "content" : "book"
        } ],
        "additional_services" : {
          "cod" : {
            "status" : true,
            "amount" : 0
          }
        },
        "courier" : {
          "service" : "dpd_standard",
          "pickup" : {
            "type" : "courier",
            "date" : "2025-04-09",
            "time" : "13:00"
          }
        }
      },
      "shipment_type" : "primary",
      "user_id" : 105338,
      "user_bank_account_id" : 17311,
      "courier_id" : 2,
      "service_id" : 42,
      "api_id" : "2505",
      "sender_locality" : {
        "id" : 13751,
        "county_id" : 10,
        "name" : "Bucuresti",
        "municipality" : "Sectorul 1",
        "keywords" : "Bucuresti Bucuresti",
        "postal_code" : "010011",
        "has_streets" : true,
        "population" : 1883425,
        "latitude" : "26.10272000",
        "longitude" : "44.43614100",
        "dpd_site_id" : 642279132,
        "dpd_serving_days" : "1111110",
        "sameday_city_id" : 1,
        "sameday_county_id" : 1,
        "courier_locations" : [ {
          "id" : 90784,
          "courier_id" : 10,
          "locality_id" : 13751,
          "locality_alias" : "Bucuresti",
          "distance" : 0,
          "zone" : null
        }, {
          "id" : 90919,
          "courier_id" : 3,
          "locality_id" : 13751,
          "locality_alias" : "BUCURESTI",
          "distance" : 0,
          "zone" : null
        } ]
      },
      "receiver_locality" : {
        "id" : 13751,
        "county_id" : 10,
        "name" : "Bucuresti",
        "municipality" : "Sectorul 1",
        "keywords" : "Bucuresti Bucuresti",
        "postal_code" : "010011",
        "has_streets" : true,
        "population" : 1883425,
        "latitude" : "26.10272000",
        "longitude" : "44.43614100",
        "dpd_site_id" : 642279132,
        "dpd_serving_days" : "1111110",
        "sameday_city_id" : 1,
        "sameday_county_id" : 1,
        "courier_locations" : [ {
          "id" : 90784,
          "courier_id" : 10,
          "locality_id" : 13751,
          "locality_alias" : "Bucuresti",
          "distance" : 0,
          "zone" : null
        }, {
          "id" : 90919,
          "courier_id" : 3,
          "locality_id" : 13751,
          "locality_alias" : "BUCURESTI",
          "distance" : 0,
          "zone" : null
        } ]
      },
      "volumetric_weight_divider" : 5000,
      "billing_weight" : 10,
      "price_net" : 24.880000000000003,
      "price_gross" : 29.61,
      "fees" : {
        "base" : {
          "value" : 14.3
        },
        "extra_kg" : {
          "value" : 7
        },
        "minimum_wage" : {
          "value" : 0.91
        },
        "fuel_surcharge" : {
          "value" : 2.67
        }
      },
      "payment_amount" : 29.61
    },
    "source" : "external_api",
    "source_order_id" : null,
    "created_at" : "2025-04-08T11:58:57.000000Z",
    "imported_order_created_at" : "2025-04-08T11:58:57.000000Z"
  }
}
';
        $decodedJson = json_decode($json, true, 12, JSON_THROW_ON_ERROR);

        $orderToSend = Json::mapArrayToObject($decodedJson['order_to_send'], EcoletOrderSendResponse::class);

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