<?php

namespace PostenBringCheckout\admin\bring\models\booking;

defined( 'ABSPATH' ) || exit;

class Parties {
	public Party $sender;
	public Party $recipient;
	public ?PickupPoint $pickupPoint;
	public ?Party $importer;
	public ?Party $exporter;

	public function __construct( Party $sender, Party $recipient, ?PickupPoint $pickupPoint = null, ?Party $importer = null, ?Party $exporter = null ) {
		$this->sender      = $sender;
		$this->recipient   = $recipient;
		$this->pickupPoint = $pickupPoint;
		$this->importer    = $importer;
		$this->exporter    = $exporter;
	}

	public function toArray(): array {
		$data = array_filter( get_object_vars( $this ), fn( $value ) => $value !== null );
		if ( $this->pickupPoint ) {
			$data['pickupPoint'] = $this->pickupPoint->toArray();
		}
		return $data;
	}
}
