<?php

namespace DhlPolska\API\WebApi\Struct;

use DhlPolska\API\ShipmentDataInterface;

/**
 * ShipmentFullData structure.
 */
class ShipmentFullData implements ShipmentDataInterface {

	/** @var AddressData */
	private AddressData $shipper;

	/** @var ReceiverAddressData */
	private ReceiverAddressData $receiver;

	/** @var mixed|null */
	private $neighbour;

	/** @var PaymentData */
	private PaymentData $payment;

	/** @var ServiceDefinition */
	private ServiceDefinition $service;

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

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

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

	/** @var PieceDefinition[] */
	private array $piece_list;

	/** @var bool */
	private bool $skip_restriction_check;

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

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

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

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

	/** @var mixed|null */
	private $customs;

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

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

	/**
	 * ShipmentFullData constructor.
	 *
	 * @param bool                $skip_restriction_check
	 * @param AddressData         $shipper
	 * @param ReceiverAddressData $receiver
	 * @param PaymentData         $payment
	 * @param ServiceDefinition   $service
	 * @param string              $shipment_date
	 * @param string              $content
	 * @param PieceDefinition[]   $piece_list
	 * @param string|null         $comment
	 * @param string|null         $reference
	 * @param int|null            $shipment_id
	 * @param string|null         $created
	 * @param string|null         $order_status
	 * @param string|null         $way_bill
	 * @param string|null         $service_point_account_number
	 * @param mixed|null          $neighbour
	 * @param mixed|null          $customs
	 */
	public function __construct(
		bool $skip_restriction_check,
		AddressData $shipper,
		ReceiverAddressData $receiver,
		PaymentData $payment,
		ServiceDefinition $service,
		string $shipment_date,
		string $content,
		array $piece_list,
		?string $comment = null,
		?string $reference = null,
		?int $shipment_id = null,
		?string $created = null,
		?string $order_status = null,
		?string $way_bill = null,
		?string $service_point_account_number = null,
		$neighbour = null,
		$customs = null
	) {
		$this->skip_restriction_check       = $skip_restriction_check;
		$this->shipper                      = $shipper;
		$this->receiver                     = $receiver;
		$this->payment                      = $payment;
		$this->service                      = $service;
		$this->shipment_date                = $shipment_date;
		$this->content                      = $content;
		$this->piece_list                   = $piece_list;
		$this->comment                      = $comment;
		$this->reference                    = $reference;
		$this->shipment_id                  = $shipment_id;
		$this->created                      = $created;
		$this->order_status                 = $order_status;
		$this->way_bill                     = $way_bill;
		$this->service_point_account_number = $service_point_account_number;
		$this->neighbour                    = $neighbour;
		$this->customs                      = $customs;
	}

	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return array_filter(
			[
				'shipper'                   => $this->shipper,
				'receiver'                  => $this->receiver,
				'neighbour'                 => $this->neighbour,
				'pieceList'                 => $this->piece_list,
				'payment'                   => $this->payment,
				'service'                   => $this->service,
				'shipmentDate'              => $this->shipment_date,
				'skipRestrictionCheck'      => $this->skip_restriction_check,
				'comment'                   => $this->comment,
				'content'                   => $this->content,
				'reference'                 => $this->reference,
				'shipmentId'                => $this->shipment_id,
				'created'                   => $this->created,
				'orderStatus'               => $this->order_status,
				'customs'                   => $this->customs,
				'wayBill'                   => $this->way_bill,
				'servicePointAccountNumber' => $this->service_point_account_number,
			],
			static fn ( $value ) => $value !== null
		);
	}
}
