<?php

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

/**
 * ReceiverAddressat structure for createShipment.
 */
class ReceiverAddressat implements JsonSerializable {

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

	/** @var PreavisoContact|null */
	private ?PreavisoContact $contact;

	/** @var ReceiverAddress|null */
	private ?ReceiverAddress $address;

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

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