<?php

namespace DhlPolska\API\WebApi\Method;

use DhlPolska\API\AuthDataInterface;
use JsonSerializable;

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

	/**
	 * @var AuthDataInterface
	 */
	private AuthDataInterface $auth_data;

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

	/**
	 * CancelCourierBooking constructor.
	 *
	 * @param AuthDataInterface $auth_data
	 * @param string[] $booking_ids
	 */
	public function __construct( AuthDataInterface $auth_data, array $booking_ids ) {
		$this->auth_data   = $auth_data;
		$this->booking_ids = $booking_ids;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		$orders = $this->booking_ids;
		if ( 1 === count( $orders ) ) {
			$orders = (string) reset( $orders );
		}

		return [
			'authData' => $this->auth_data,
			'orders'   => $orders,
		];
	}
}
