<?php

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

/**
 * ShipmentInfo structure for createShipment.
 */
class ShipmentInfo implements JsonSerializable {

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

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

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

	/** @var Service[] */
	private array $special_services;

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

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

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

	/**
	 * ShipmentInfo constructor.
	 *
	 * @param string        $drop_off_type
	 * @param string        $service_type
	 * @param BillingData   $billing
	 * @param ShipmentTime  $shipment_time
	 * @param string        $label_type
	 * @param Service[]     $special_services
	 * @param string|null   $way_bill
	 */
	public function __construct(
		string $drop_off_type,
		string $service_type,
		BillingData $billing,
		ShipmentTime $shipment_time,
		string $label_type = 'BLP',
		array $special_services = [],
		?string $way_bill = null
	) {
		$this->drop_off_type    = $drop_off_type;
		$this->service_type     = $service_type;
		$this->billing          = $billing;
		$this->special_services = $special_services;
		$this->shipment_time    = $shipment_time;
		$this->label_type       = $label_type;
		$this->way_bill         = $way_bill;
	}

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