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

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

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

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

	/** @var bool */
	private bool $book_courier;

	/** @var BillingData */
	private BillingData $billing;

	/** @var array<int, mixed>|null */
	private ?array $special_services;

	/** @var ReturnShipmentTime */
	private ReturnShipmentTime $shipment_time;

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

	/**
	 * ReturnShipmentInfo constructor.
	 *
	 * @param string             $service_type
	 * @param bool               $book_courier
	 * @param BillingData        $billing
	 * @param ReturnShipmentTime $shipment_time
	 * @param string|null        $label_type
	 * @param array<int, mixed>|null $special_services
	 */
	public function __construct(
		string $service_type,
		bool $book_courier,
		BillingData $billing,
		ReturnShipmentTime $shipment_time,
		?string $label_type = null,
		?array $special_services = null
	) {
		$this->service_type     = $service_type;
		$this->book_courier     = $book_courier;
		$this->billing          = $billing;
		$this->shipment_time    = $shipment_time;
		$this->label_type       = $label_type;
		$this->special_services = $special_services;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'serviceType'     => $this->service_type,
				'bookCourier'     => $this->book_courier,
				'billing'         => $this->billing,
				'specialServices' => $this->special_services,
				'shipmentTime'    => $this->shipment_time,
				'labelType'       => $this->label_type,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
