<?php

declare(strict_types=1);

namespace Autogedal\AwbRetry\Model;

class TransientFailureClassifier
{
    public function __construct(
        private readonly Config $config
    ) {
    }

    public function isTransient(\Throwable $throwable): bool
    {
        $message = strtolower($throwable->getMessage());

        foreach ($this->config->getTransientFailurePatterns() as $pattern) {
            if ($pattern !== '' && str_contains($message, strtolower($pattern))) {
                return true;
            }
        }

        return false;
    }
}
