<?php

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

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

	/** @var Addressat */
	private Addressat $shipper;

	/** @var ReceiverAddressat */
	private ReceiverAddressat $receiver;

	/** @var mixed|null */
	private $neighbour;

	/** @var string|null */
	private ?string $service_point_account_number;

	/**
	 * Ship constructor.
	 *
	 * @param Addressat         $shipper
	 * @param ReceiverAddressat $receiver
	 * @param mixed|null        $neighbour
	 * @param string|null       $service_point_account_number
	 */
	public function __construct(
		Addressat $shipper,
		ReceiverAddressat $receiver,
		$neighbour = null,
		?string $service_point_account_number = null
	) {
		$this->shipper                      = $shipper;
		$this->receiver                     = $receiver;
		$this->neighbour                    = $neighbour;
		$this->service_point_account_number = $service_point_account_number;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'shipper'                   => $this->shipper,
				'receiver'                  => $this->receiver,
				'neighbour'                 => $this->neighbour,
				'servicePointAccountNumber' => $this->service_point_account_number,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
