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

namespace DhlPolska\API\WebApi\Struct;

use JsonSerializable;

/**
 * ShipperAddress structure for return shipments.
 */
class ShipperAddress implements JsonSerializable {

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

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

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

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

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

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

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

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

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