<?php

namespace App\Exceptions;

use RuntimeException;

class CorreosCostaRicaException extends RuntimeException
{
    public function __construct(
        public readonly string $codigo,
        public readonly ?string $mensaje = null,
        ?\Throwable $previous = null,
    ) {
        parent::__construct($this->buildMessage(), 0, $previous);
    }

    protected function buildMessage(): string
    {
        $msg = 'Correos CR error';

        if ($this->codigo !== '') {
            $msg .= " (CodRespuesta={$this->codigo})";
        }

        if (filled($this->mensaje)) {
            $msg .= ": {$this->mensaje}";
        }

        return $msg;
    }
}
