<?php

namespace App\Data\Validation;

class ValidationResult
{
    private bool $error;
    private ?string $errorMessage;

    public function __construct(bool $error, ?string $errorMessage = null)
    {
        $this->error = $error;
        $this->errorMessage = $errorMessage;
    }

    /**
     * @return void|never
     */
    final public function assertIsSuccess(): void
    {
        if ($this->isError()) {
            throw new ValidationException($this->getErrorMessage());
        }
    }

    public function isError(): bool
    {
        return $this->error;
    }

    public function isSuccess(): bool
    {
        return !$this->isError();
    }

    public function getErrorMessage(): ?string
    {
        return $this->errorMessage;
    }
}
