<?php

namespace Planaday\Api\Mock;

use ArrayAccess;
use Countable;
use Planaday\Entities\Booking\BookingApi;
use Planaday\Entities\Booking\DTO\BookingForm;
use Planaday\Entities\Booking\DTO\BookingResponse;
use Planaday\Entities\Booking\DTO\ExtraField;
use Planaday\Utility\DataGrouping\Collection;
use Planaday\Utility\Debug\Log\Logging;
use Traversable;

class MockBookingApi implements BookingApi {
	use Logging;
	public BookingApi|null $bookingApiMock = null;

	/**
	 * @inheritDoc
	 */
	public function doBooking( BookingForm $bookingForm ): BookingResponse {
		$this->logInfo("MockBookingApi doing booking", $bookingForm);
		return $this->bookingApiMock?->doBooking($bookingForm) ?? (new BookingResponse())
			->setBookingId("1234567890")
			->setResult("OK");
	}

	/**
	 * @inheritDoc
	 */
	public function postPaymentDataBooking( string $bookingId, string $transactionId ): bool {
		$this->logInfo("MockBookingApi posting payment data for booking $bookingId");
		return $this->bookingApiMock?->postPaymentDataBooking($bookingId, $transactionId) ?? true;
	}

	/**
	 * @inheritDoc
	 */
	public function deleteBookingAfterNoPayment( string $bookingId, string $transactionId ): void {
		$this->bookingApiMock?->deleteBookingAfterNoPayment($bookingId, $transactionId);
		$this->logInfo("MockBookingApi deleting booking $bookingId after no payment");
	}

	/**
	 * @inheritDoc
	 */
	public function getExtraFieldsList(): ArrayAccess&Traversable&Countable {
		return $this->bookingApiMock?->getExtraFieldsList() ??
			 new Collection(
				(new ExtraField(12))
					->setName("test extra field")
					->setDescription("dit is een test extra veld")
					->setOptions([
						1,2,3
					])
					->setType("radio")
					->setDefaultValue(1)
			 );
	}
}