<?php

namespace PostenBringCheckout\admin\bring\models\booking;

defined( 'ABSPATH' ) || exit;

class Product {
	public string $id;
	public string $customerNumber;
	public ?EdiCustomsDeclaration $ediCustomsDeclarations;
	public ?array $additionalServices;

	public function __construct(
		string $id,
		string $customerNumber,
		?EdiCustomsDeclaration $ediCustomsDeclarations = null,
		?array $additionalServices = null
	) {
		$this->id                     = $id;
		$this->customerNumber         = $customerNumber;
		$this->ediCustomsDeclarations = $ediCustomsDeclarations;
		$this->additionalServices     = $additionalServices;
	}

	public function toArray(): array {
		$data = get_object_vars( $this );
		if ( $this->additionalServices ) {
			$data['additionalServices'] = array_map(
				function ( $service ) {
					return $service->toArray();
				},
				$this->additionalServices
			);
		}
		return $data;
	}
}
