<?php

namespace Planaday\Config\OptionGroups\Course;

use Planaday\Platform\PlatformAbstraction\DataHandler;

class CourseOptionsPostService {
	private $error;

	/** @var CourseOptionsValidator */
	private $courseOptionsValidator;

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

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

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

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

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

}