<?php
/**
 * Class BookCourier
 *
 * @package DhlPolska\API\WebApi\Method
 */

namespace DhlPolska\API\WebApi\Method;

use DhlPolska\API\AuthDataInterface;
use DhlPolska\API\WebApi\Struct\ShipmentOrderInfo;
use JsonSerializable;

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

	private AuthDataInterface $auth_data;

	private string $pickup_date;

	private string $pickup_time_from;

	private string $pickup_time_to;

	private string $additional_info;

	/**
	 * @var string[]
	 */
	private array $shipment_id_list;

	private ?ShipmentOrderInfo $shipment_order_info;

	private ?bool $courier_with_label;

	/**
	 * @param AuthDataInterface   $auth_data .
	 * @param string              $pickup_date .
	 * @param string              $pickup_time_from .
	 * @param string              $pickup_time_to .
	 * @param string              $additional_info .
	 * @param string[]            $shipment_id_list .
	 * @param ShipmentOrderInfo|null $shipment_order_info .
	 * @param bool|null           $courier_with_label .
	 */
	public function __construct(
		AuthDataInterface $auth_data,
		string $pickup_date,
		string $pickup_time_from,
		string $pickup_time_to,
		string $additional_info,
		array $shipment_id_list,
		?ShipmentOrderInfo $shipment_order_info = null,
		?bool $courier_with_label = null
	) {
		$this->auth_data           = $auth_data;
		$this->pickup_date         = $pickup_date;
		$this->pickup_time_from    = $pickup_time_from;
		$this->pickup_time_to      = $pickup_time_to;
		$this->additional_info     = $additional_info;
		$this->shipment_id_list    = $shipment_id_list;
		$this->shipment_order_info = $shipment_order_info;
		$this->courier_with_label  = $courier_with_label;
	}

	public function jsonSerialize(): array {
		return array_filter(
			[
				'authData'          => $this->auth_data,
				'pickupDate'        => $this->pickup_date,
				'pickupTimeFrom'    => $this->pickup_time_from,
				'pickupTimeTo'      => $this->pickup_time_to,
				'additionalInfo'    => $this->additional_info,
				'shipmentIdList'    => $this->shipment_id_list,
				'shipmentOrderInfo' => $this->shipment_order_info,
				'courierWithLabel'  => $this->courier_with_label,
			],
			static fn ( $value ) => $value !== null && $value !== ''
		);
	}
}
