<?php

namespace Alsendo\AlsendoWrapper\Api\Zaslat\Wrapper;

use Alsendo\AlsendoWrapper\Api\Zaslat\Model\AddressBookListResponse;
use Alsendo\AlsendoWrapper\Api\Zaslat\Model\ZaslatAddressBook;
use Alsendo\AlsendoWrapper\Json;

class AddressBookListResponseWrapper
{
    public static function wrap(array $data): AddressBookListResponse
    {
        $addresses = [];
        foreach ($data as $addressId => $contactData) {
            if (is_array($contactData)) {
                $addresses[(string)$addressId] = Json::mapArrayToObject($contactData, ZaslatAddressBook::class);
            }
        }

        return new AddressBookListResponse($addresses);
    }
}
