<?php

namespace Planaday\Utility\FormBuilder\SubmitStrategies;

use Planaday\Utility\FormBuilder\SubmitStrategy;

class RestSubmit implements SubmitStrategy{
	protected string $url = '';
	protected array $headers = [];
	protected bool $saveDataOnSuccess = false;

	public function setUrl(string $url): self {
		$this->url = $url;
		return $this;
	}

	public function setHeaders(array $headers): self {
		$this->headers = $headers;
		return $this;
	}

	public function setSaveDataOnSuccess(bool $saveDataOnSuccess): self {
		$this->saveDataOnSuccess = $saveDataOnSuccess;
		return $this;
	}

	public function jsonSerialize(): array {
		return [
			"type" => "rest",
			"url" => $this->url,
			"headers" => $this->headers,
			"saveDataOnSuccess" => $this->saveDataOnSuccess,
		];
	}
}