<?php

app_require('modules/economic/customers/economic_customer_mo.php');

use customers\economic_customer_mo;

if (!class_exists('EconomicCustomerModelParsingProbe')) {
    class EconomicCustomerModelParsingProbe extends economic_customer_mo
    {
        protected function cacheCustomerForImportedUser(): void
        {
        }
    }
}

it('parses cached economic customer payloads that use snake_case customer_number', function (): void {
    $model = (new EconomicCustomerModelParsingProbe())->parseCustomer((object)[
        'customer_number' => '42331123',
        'name' => 'Truckwash ApS',
        'email' => 'jb@truckwash.dk',
        'ean' => '5790001234567',
        'public_entry_number' => 'DK123456789',
        'currency' => 'DKK',
        'country' => 'DK',
        'barred' => true,
    ]);

    expect($model->asArray())->toBe([
        'customerNumber' => 42331123,
        'name' => 'Truckwash ApS',
        'address' => null,
        'city' => null,
        'zip' => null,
        'corporateIdentificationNumber' => null,
        'email' => 'jb@truckwash.dk',
        'ean' => '5790001234567',
        'publicEntryNumber' => 'DK123456789',
        'mobilePhone' => null,
        'currency' => 'DKK',
        'country' => 'DK',
        'barred' => true,
    ]);
});

it('leaves the economic customer model empty when no valid customer number is present', function (): void {
    $model = (new EconomicCustomerModelParsingProbe())->parseCustomer((object)[
        'name' => 'Missing Number',
    ]);

    expect($model->asArray())->toBe([]);
});
