package space.nstart.pcp.routepassportconsumer.config

import jakarta.validation.constraints.AssertTrue
import jakarta.validation.constraints.Min
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.validation.annotation.Validated

/**
 * Operational settings for the route passport outbox worker.
 *
 * Values control scheduling cadence, DB claim size, lock lease time and bounded retry backoff.
 */
@Validated
@ConfigurationProperties(prefix = "app.route-passport.outbox")
data class RoutePassportOutboxProperties(

    /** Enables scheduled publication of pending route passport outbox rows. */
    val enabled: Boolean = true,

    /** Maximum number of due rows claimed by one worker tick. */
    @field:Min(1)
    val batchSize: Int = 50,

    /** Delay between scheduled worker runs. */
    @field:Min(100)
    val fixedDelayMs: Long = 1_000,

    /** Lease duration for a claimed row; expired locks can be claimed by another instance. */
    @field:Min(1_000)
    val lockTimeoutMs: Long = 60_000,

    /** Backoff after the first failed publication attempt. */
    @field:Min(100)
    val initialBackoffMs: Long = 1_000,

    /** Maximum backoff between publication attempts. */
    @field:Min(100)
    val maxBackoffMs: Long = 60_000,
) {

    @get:AssertTrue(message = "maxBackoffMs must be greater than or equal to initialBackoffMs")
    val isMaxBackoffGreaterThanOrEqualToInitialBackoff: Boolean
        get() = maxBackoffMs >= initialBackoffMs
}
