<?php

namespace DhlPolska\API\ParcelShop\Struct;

use JsonSerializable;

/**
 * Special service structure for ParcelShop API.
 */
class SpecialService implements JsonSerializable {

	public const TYPE_UBEZP = 'UBEZP';
	public const TYPE_COD   = 'COD';

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

	/** @var int|null */
	private ?int $service_value;

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

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

	/**
	 * SpecialService constructor.
	 *
	 * @param string      $service_type
	 * @param int|null    $service_value
	 * @param string|null $text_instruction
	 * @param string|null $collect_on_delivery_form
	 */
	public function __construct(
		string $service_type,
		?int $service_value = null,
		?string $text_instruction = null,
		?string $collect_on_delivery_form = null
	) {
		$this->service_type             = $service_type;
		$this->service_value            = $service_value;
		$this->text_instruction         = $text_instruction;
		$this->collect_on_delivery_form = $collect_on_delivery_form;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'serviceType'           => $this->service_type,
				'serviceValue'          => $this->service_value,
				'textInstruction'       => $this->text_instruction,
				'collectOnDeliveryForm' => $this->collect_on_delivery_form,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
