<?php

namespace DhlPolska\API\ParcelShop\Struct;

use DhlPolska\API\ShipmentDataInterface;

/**
 * ShipmentData structure for ParcelShop API.
 */
class ShipmentData implements ShipmentDataInterface {

	/** @var Ship */
	private Ship $ship;

	/** @var ShipmentInfo */
	private ShipmentInfo $shipment_info;

	/** @var PieceDefinition[] */
	private array $piece_list;

	/** @var string */
	private string $content;

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

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

	/**
	 * ShipmentData constructor.
	 *
	 * @param Ship              $ship
	 * @param ShipmentInfo      $shipment_info
	 * @param PieceDefinition[] $piece_list
	 * @param string            $content
	 * @param string|null       $comment
	 * @param string|null       $reference
	 */
	public function __construct(
		Ship $ship,
		ShipmentInfo $shipment_info,
		array $piece_list,
		string $content,
		?string $comment = null,
		?string $reference = null
	) {
		$this->ship          = $ship;
		$this->shipment_info = $shipment_info;
		$this->piece_list    = $piece_list;
		$this->content       = $content;
		$this->comment       = $comment;
		$this->reference     = $reference;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'ship'         => $this->ship,
				'shipmentInfo' => $this->shipment_info,
				'pieceList'    => $this->piece_list,
				'content'      => $this->content,
				'comment'      => $this->comment,
				'reference'    => $this->reference,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
