<?php

declare(strict_types=1);

namespace App\Exceptions\Billing;

use RuntimeException;

/**
 * Выбрасывается LedgerService::chargeForDelivery, когда tenant не имеет
 * ни prepaid-лидов (balance_leads >= 1), ни рублей под текущую tier-цену
 * (balance_rub * 100 >= priceKopecks).
 *
 * Ловится в RouteSupplierLeadJob::createDealCopyForProject — инициирует
 * auto-pause flow (см. spec §4.2).
 */
final class InsufficientBalanceException extends RuntimeException
{
    public function __construct(
        public readonly int $priceKopecks,
        public readonly string $balanceRub,
        public readonly int $balanceLeads,
        ?\Throwable $previous = null,
    ) {
        parent::__construct(
            sprintf(
                'Insufficient balance: price_kopecks=%d, balance_rub=%s, balance_leads=%d',
                $priceKopecks, $balanceRub, $balanceLeads,
            ),
            previous: $previous,
        );
    }
}
