package com.correx.core.events.execution

import kotlinx.serialization.Serializable

@Serializable
data class RetryPolicy(
    val maxAttempts: Int,
    val backoffMs: Long = 1_000L,
    // Per-gate override (design 2026-07-06-per-gate-retry-budgets.md §8): a gate id present here uses
    // its own budget instead of [maxAttempts]. Empty by default — every gate then independently gets
    // [maxAttempts] (un-shared, per T2/T5), preserving today's numbers with no TOML changes required.
    val perGateMaxAttempts: Map<String, Int> = emptyMap(),
) {
    init {
        require(maxAttempts >= 1) { "maxAttempts must be >= 1" }
        require(perGateMaxAttempts.values.all { it >= 1 }) { "perGateMaxAttempts values must be >= 1" }
    }

    fun maxAttemptsFor(gate: String): Int = perGateMaxAttempts[gate] ?: maxAttempts
}
