<?php

namespace App\Exceptions;

use RuntimeException;

class LogisticsApiException extends RuntimeException
{
    public function __construct(
        string $message,
        public readonly string $endpoint = '',
        public readonly array $params = [],
        int $code = 0,
        ?\Throwable $previous = null,
    ) {
        parent::__construct($message, $code, $previous);
    }

    public static function connectionTimeout(string $endpoint, array $params, \Throwable $previous): self
    {
        return new self(
            message: "L'API Logistics est injoignable. Verifiez que le serveur est accessible et que votre connexion reseau fonctionne.",
            endpoint: $endpoint,
            params: $params,
            previous: $previous,
        );
    }

    public static function requestFailed(string $endpoint, array $params, \Throwable $previous): self
    {
        return new self(
            message: "La requete vers l'API Logistics a echoue : {$previous->getMessage()}",
            endpoint: $endpoint,
            params: $params,
            previous: $previous,
        );
    }
}
