<?php declare(strict_types=1); namespace App\ServiceResults; use App\Contracts\ServiceResultError as ServiceResultErrorContract; final class ServiceResultError extends ServiceResult implements ServiceResultErrorContract { public function __construct( private readonly string $message, private readonly array $errors = [], private readonly ?int $code = null, ) { } public function getMessage(): string { return $this->message; } public function getCode(): ?int { return $this->code; } public function getErrors(): array { return $this->errors; } public function getErrorsOrMessage(): array|string { if (!empty($this->getErrors())) { return $this->getErrors(); } return $this->getMessage(); } public function getData(): array { return [ 'message' => $this->getMessage(), 'errors' => $this->errors ]; } }