<?php

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

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

	private AddressData $shipper;

	private ?int $number_of_ex_pieces;

	private ?int $number_of_dr_pieces;

	private ?int $total_weight;

	private ?int $heaviest_piece_weight;

	public function __construct(
		AddressData $shipper,
		?int $number_of_ex_pieces,
		?int $number_of_dr_pieces,
		?int $total_weight,
		?int $heaviest_piece_weight
	) {
		$this->shipper               = $shipper;
		$this->number_of_ex_pieces   = $number_of_ex_pieces;
		$this->number_of_dr_pieces   = $number_of_dr_pieces;
		$this->total_weight          = $total_weight;
		$this->heaviest_piece_weight = $heaviest_piece_weight;
	}

	public function jsonSerialize(): array {
		return array_filter(
			[
				'shipper'             => $this->shipper,
				'numberOfExPieces'    => $this->number_of_ex_pieces,
				'numberOfDrPieces'    => $this->number_of_dr_pieces,
				'totalWeight'         => $this->total_weight,
				'heaviestPieceWeight' => $this->heaviest_piece_weight,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
