<?php

namespace Planaday\Config\OptionGroups\Payment;

use Planaday\Platform\PlatformAbstraction\DataHandler;

class PaymentOptionsPostService {
	private $error;

	/** @var PaymentOptionsValidator */
	private $paymentOptionsValidator;

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

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

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

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

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