<?php
declare(strict_types=1);

namespace App\Support;

use InvalidArgumentException;
use Throwable;

final class TranslatableException extends InvalidArgumentException
{
    public function __construct(public readonly string $translationKey, public readonly array $replace = [], string $message = '', ?Throwable $previous = null)
    {
        parent::__construct($message !== '' ? $message : $translationKey, 0, $previous);
    }

    public function translate(Translator $translator): string
    {
        return $translator->get($this->translationKey, $this->replace);
    }
}
