package wang.yaojia.webterm.wire

import kotlinx.serialization.Serializable

/**
 * Per-session statusLine telemetry (B2), broadcast in a `telemetry` frame. FROZEN shape,
 * mirrors `src/types.ts:412-422` `StatusTelemetry` and iOS `WireProtocol.StatusTelemetry`.
 *
 * Every metric is OPTIONAL; [at] (server receive time, ms since epoch) is REQUIRED — a frame
 * without it is dropped by A4's decoder. Property names match the server JSON keys exactly so
 * the tolerant `Json` decode configured in A4 maps them directly. `@Serializable` here only
 * freezes the SHAPE; the tolerant-decode CONFIG (ignoreUnknownKeys / wrong-typed-optional ->
 * absent) lives in A4.
 */
@Serializable
public data class StatusTelemetry(
    val contextUsedPct: Double? = null,
    val costUsd: Double? = null,
    val linesAdded: Int? = null,
    val linesRemoved: Int? = null,
    val model: String? = null,
    val effort: String? = null,
    val pr: PrInfo? = null,
    val rate: RateInfo? = null,
    /** Server receive timestamp (ms since epoch). REQUIRED — frames without it are dropped. */
    val at: Long,
)

/** Pull-request summary carried in [StatusTelemetry.pr] (`src/types.ts:419`). */
@Serializable
public data class PrInfo(
    val number: Int,
    val url: String,
    val reviewState: String? = null,
)

/** Rate-limit summary carried in [StatusTelemetry.rate] (`src/types.ts:420`). */
@Serializable
public data class RateInfo(
    val fiveHourPct: Double? = null,
    val sevenDayPct: Double? = null,
)
