<?php

namespace Planaday\Config\OptionGroups\Booking;

use Planaday\Platform\PlatformAbstraction\DataHandler;

class BookingOptionsPostService {
	private $error;

	/** @var BookingOptionsValidator */
	private $bookingOptionsValidator;

	/** @var DataHandler */
	private $dataHandler;

	public function __construct( BookingOptionsValidator $bookingOptionsValidator, DataHandler $dataHandler) {
		$this->bookingOptionsValidator = $bookingOptionsValidator;
		$this->dataHandler = $dataHandler;
	}

	public function checkAndHandlePostData(array $postData):void {
		if (!$this->bookingOptionsValidator->validate($postData, $data)) {
			$this->error = $data;
			return;
		}

		$this->dataHandler->setOption(BookingOptions::INDEX, $data);
	}

	public function getError() {
		return $this->error;
	}

}