<?php

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

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

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

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

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

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

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

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

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

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

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

	/**
	 * PieceDefinition constructor.
	 *
	 * @param string      $type
	 * @param int         $quantity
	 * @param float|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
	 * @param bool|null   $euro_return
	 */
	public function __construct(
		string $type,
		int $quantity,
		?float $weight = null,
		?int $width = null,
		?int $height = null,
		?int $length = null,
		?bool $non_standard = null,
		?string $blp_piece_id = null,
		?bool $euro_return = 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;
		$this->euro_return  = $euro_return;
	}

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