<?php

namespace Planaday\Config\OptionGroups\General;

use Planaday\Platform\PlatformAbstraction\DataHandler;

class GeneralOptionsPostService {
	private $error;

	/** @var GeneralOptionsValidator */
	private $generalOptionsValidator;

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

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

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

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

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

}