<?php

namespace PostenBringCheckout\admin\bring\models\booking;

defined( 'ABSPATH' ) || exit;

class Consignment {
	public string $shippingDateTime;
	public Parties $parties;
	public Product $product;
	public array $packages;
	public ?string $correlationId;
	public ?string $customerSpecifiedDeliveryDateTime;

	public function __construct(
		string $shippingDateTime,
		Parties $parties,
		Product $product,
		array $packages = array(),
		?string $correlationId = null,
		?string $customerSpecifiedDeliveryDateTime = null
	) {
		$this->shippingDateTime                  = $shippingDateTime;
		$this->parties                           = $parties;
		$this->product                           = $product;
		$this->packages                          = $packages;
		$this->correlationId                     = $correlationId;
		$this->customerSpecifiedDeliveryDateTime = $customerSpecifiedDeliveryDateTime;
	}

	public function toArray(): array {
		$data            = get_object_vars( $this );
		$data['parties'] = $this->parties->toArray();
		$data['product'] = $this->product->toArray();
		$data['packages'] = array_map(
			function ( $package ) {
				return $package->toArray();
			},
			$this->packages
		);
		return $data;
	}
}
