package space.nstart.pcp.routepassportconsumer.service

import io.micrometer.core.instrument.Counter
import io.micrometer.core.instrument.MeterRegistry
import org.springframework.stereotype.Component

/**
 * Centralizes route passport counters so operational metrics names stay consistent.
 */
@Component
class RoutePassportMetrics(
    meterRegistry: MeterRegistry,
) {
    private val ingestSuccessCounter = meterRegistry.counter("route_passport_ingest_success_total")
    private val ingestFailureCounter = meterRegistry.counter("route_passport_ingest_failure_total")
    private val outboxPublishedCounter = meterRegistry.counter("route_passport_outbox_published_total")
    private val outboxRetryCounter = meterRegistry.counter("route_passport_outbox_retry_total")
    private val outboxFailedCounter = meterRegistry.counter("route_passport_outbox_failed_total")

    fun incrementIngestSuccess() {
        ingestSuccessCounter.increment()
    }

    fun incrementIngestFailure() {
        ingestFailureCounter.increment()
    }

    fun incrementOutboxPublished() {
        outboxPublishedCounter.increment()
    }

    fun incrementOutboxRetry() {
        outboxRetryCounter.increment()
    }

    fun incrementOutboxFailed() {
        outboxFailedCounter.increment()
    }

    private fun MeterRegistry.counter(name: String): Counter =
        Counter.builder(name).register(this)
}
