<?php

namespace DhlPolska\API\ParcelShop\Struct;

use JsonSerializable;

/**
 * AddressData structure for ParcelShop API.
 */
class AddressData implements JsonSerializable {

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

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

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

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

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

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

	/**
	 * AddressData constructor.
	 *
	 * @param string      $name
	 * @param string      $street
	 * @param string      $house_number
	 * @param string      $city
	 * @param string      $postal_code
	 * @param string|null $apartment_number
	 */
	public function __construct(
		string $name,
		string $street,
		string $house_number,
		string $city,
		string $postal_code,
		?string $apartment_number = null
	) {
		$this->name             = $name;
		$this->street           = $street;
		$this->house_number     = $house_number;
		$this->city             = $city;
		$this->postal_code      = $postal_code;
		$this->apartment_number = $apartment_number;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'name'            => $this->name,
				'postcode'        => $this->postal_code,
				'city'            => $this->city,
				'street'          => $this->street,
				'houseNumber'     => $this->house_number,
				'apartmentNumber' => $this->apartment_number,
			],
			static fn ( $value ) => $value !== null,
		);
	}
}
