<?php
/**
 * Class CreateReturnShipmentRequest
 *
 * @package DhlPolska\API\WebApi\Struct
 */

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

/**
 * CreateReturnShipmentRequest structure.
 */
class CreateReturnShipmentRequest implements JsonSerializable {

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

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

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

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

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

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

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

	/**
	 * CreateReturnShipmentRequest constructor.
	 *
	 * @param ReturnShipmentInfo $shipment_info
	 * @param string             $content
	 * @param ReturnShip         $ship
	 * @param ReturnPackage[]    $piece_list
	 * @param string|null        $comment
	 * @param string|null        $reference
	 * @param string|null        $primary_waybill_number
	 */
	public function __construct(
		ReturnShipmentInfo $shipment_info,
		string $content,
		ReturnShip $ship,
		array $piece_list,
		?string $comment,
		?string $reference,
		?string $primary_waybill_number
	) {
		$this->shipment_info          = $shipment_info;
		$this->content                = $content;
		$this->ship                   = $ship;
		$this->piece_list             = $piece_list;
		$this->comment                = $comment;
		$this->reference              = $reference;
		$this->primary_waybill_number = $primary_waybill_number;
	}

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