<?php

namespace Planaday\Utility\FormBuilder;

use Exception;
use Throwable;

class InvalidFormDataException extends Exception {
	protected array $errors = [];

	public function __construct( string $message = "", int $code = 0, ?Throwable $previous = null ) {
		parent::__construct( $message, $code, $previous );
	}

	public function addError(?string $index, string|array $error): self {
		$index ? $this->errors[$index] = $error : $this->errors = array_merge($this->errors, $error);
		return $this;
	}

	public function getErrors(): array {
		return $this->errors;
	}
}