<?php

namespace DhlPolska\API\WebApi\Method;

use DhlPolska\API\AuthDataInterface;

/**
 * GetPostalCodeServices structure.
 */
class GetPostalCodeServices implements \JsonSerializable {

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

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

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

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

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

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

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

	/**
	 * GetPostalCodeServices constructor.
	 *
	 * @param AuthDataInterface $auth_data
	 * @param string            $post_code
	 * @param string            $pickup_date
	 * @param string|null       $city
	 * @param string|null       $street
	 * @param string|null       $house_number
	 * @param string|null       $apartment_number
	 */
	public function __construct(
		AuthDataInterface $auth_data,
		string $post_code,
		string $pickup_date,
		?string $city = null,
		?string $street = null,
		?string $house_number = null,
		?string $apartment_number = null
	) {
		$this->auth_data        = $auth_data;
		$this->post_code        = $post_code;
		$this->pickup_date      = $pickup_date;
		$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(
			[
				'authData'        => $this->auth_data,
				'postCode'        => $this->post_code,
				'pickupDate'      => $this->pickup_date,
				'city'            => $this->city,
				'street'          => $this->street,
				'houseNumber'     => $this->house_number,
				'apartmentNumber' => $this->apartment_number,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
