<?php

namespace DhlPolska\API\ParcelShop\Struct;

use JsonSerializable;

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

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

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

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

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

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