<?php

declare(strict_types=1);

namespace App\Domain\Ssl\Exceptions;

use App\Domain\Sysapi\Contracts\SysapiResult;
use RuntimeException;

class SslException extends RuntimeException
{
    public function __construct(string $message, public readonly ?SysapiResult $sysapiResult = null)
    {
        parent::__construct($message);
    }

    public static function domainNotActive(): self
    {
        return new self('Sertifika almak için domain aktif olmalı.');
    }

    public static function alreadyExists(): self
    {
        return new self('Bu domain için zaten aktif bir sertifika var.');
    }

    public static function sysapiFailed(string $op, SysapiResult $r): self
    {
        return new self("SSL {$op} başarısız (exit {$r->exitCode}): {$r->stderr}", $r);
    }
}
