<?php

app_require('modules/economic/helpers/economic_customer.php');

use helpers\economic_customer;

function economic_customer_helper_from_payload(object $payload): economic_customer
{
    $reflection = new ReflectionClass(economic_customer::class);
    /** @var economic_customer $customer */
    $customer = $reflection->newInstanceWithoutConstructor();

    $property = $reflection->getProperty('customer_data_object');
    $property->setValue($customer, $payload);

    return $customer;
}

it('exposes optional EAN and public entry number from fetched e-conomic customer data', function (): void {
    $customer = economic_customer_helper_from_payload((object)[
        'customerNumber' => 42331123,
        'ean' => ' 5790001234567 ',
        'publicEntryNumber' => ' DK123456789 ',
    ]);

    expect($customer->getEan())->toBe('5790001234567');
    expect($customer->getPublicEntryNumber())->toBe('DK123456789');
});

it('returns null for blank optional e-conomic customer recipient identifiers', function (): void {
    $customer = economic_customer_helper_from_payload((object)[
        'customerNumber' => 42331123,
        'ean' => ' ',
        'publicEntryNumber' => '',
    ]);

    expect($customer->getEan())->toBeNull();
    expect($customer->getPublicEntryNumber())->toBeNull();
});
