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

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

/**
 * Billing data structure for WebAPI return shipments.
 */
class BillingData implements JsonSerializable {

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

	/** @var int */
	private int $billing_account_number;

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

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

	/**
	 * BillingData constructor.
	 *
	 * @param string      $shipping_payment_type
	 * @param int         $billing_account_number
	 * @param string      $payment_type
	 * @param string|null $costs_center
	 */
	public function __construct(
		string $shipping_payment_type,
		int $billing_account_number,
		string $payment_type,
		?string $costs_center = null
	) {
		$this->shipping_payment_type  = $shipping_payment_type;
		$this->billing_account_number = $billing_account_number;
		$this->payment_type           = $payment_type;
		$this->costs_center           = $costs_center;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'shippingPaymentType'  => $this->shipping_payment_type,
				'billingAccountNumber' => $this->billing_account_number,
				'paymentType'          => $this->payment_type,
				'costsCenter'          => $this->costs_center,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
