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

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

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

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

	/** @var int|null */
	private ?int $weight;

	/** @var int|null */
	private ?int $width;

	/** @var int|null */
	private ?int $height;

	/** @var int|null */
	private ?int $length;

	/** @var int */
	private int $quantity;

	/** @var bool|null */
	private ?bool $non_standard;

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

	/**
	 * ReturnPackage constructor.
	 *
	 * @param string      $type
	 * @param int         $quantity
	 * @param int|null    $weight
	 * @param int|null    $width
	 * @param int|null    $height
	 * @param int|null    $length
	 * @param bool|null   $non_standard
	 * @param string|null $blp_piece_id
	 */
	public function __construct(
		string $type,
		int $quantity,
		?int $weight = null,
		?int $width = null,
		?int $height = null,
		?int $length = null,
		?bool $non_standard = null,
		?string $blp_piece_id = null
	) {
		$this->type         = $type;
		$this->quantity     = $quantity;
		$this->weight       = $weight;
		$this->width        = $width;
		$this->height       = $height;
		$this->length       = $length;
		$this->non_standard = $non_standard;
		$this->blp_piece_id = $blp_piece_id;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'type'        => $this->type,
				'weight'      => $this->weight,
				'width'       => $this->width,
				'height'      => $this->height,
				'length'      => $this->length,
				'quantity'    => $this->quantity,
				'nonStandard' => $this->non_standard,
				'blpPieceId'  => $this->blp_piece_id,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
