<?php

namespace DhlPolska\API\ParcelShop\Struct;

use JsonSerializable;

/**
 * Receiver structure for ParcelShop API.
 */
class Receiver implements JsonSerializable {

	/** @var AddressData */
	private AddressData $address;

	/** @var ContactData */
	private ContactData $contact;

	/** @var ContactData|null */
	private ?ContactData $preaviso;

	/**
	 * Receiver constructor.
	 *
	 * @param AddressData      $address
	 * @param ContactData      $contact
	 * @param ContactData|null $preaviso
	 */
	public function __construct(
		AddressData $address,
		ContactData $contact,
		?ContactData $preaviso = null
	) {
		$this->address  = $address;
		$this->contact  = $contact;
		$this->preaviso = $preaviso;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'address'  => $this->address,
				'contact'  => $this->contact,
				'preaviso' => $this->preaviso,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
