/**
 * Central home for the main-process timeouts, buffer sizes, and store caps that
 * were previously scattered as bare literals across the spawn/probe/index/store
 * modules (L10). Collecting them here makes the operational envelope reviewable
 * in one place and stops the same "how long / how big" decision drifting between
 * modules. Values that are already single-sourced in the shared contract
 * (e.g. HISTORY_MAX_ENTRIES) stay there; this file is for the main-only ones.
 */

// --- Child-process timeouts (ms) --------------------------------------------

/** `<binary> -version` probes (yt-dlp, ffmpeg, ffprobe) — a quick liveness call. */
export const VERSION_TIMEOUT_MS = 15_000
/** yt-dlp self-update run — can pull a fresh binary, so a touch longer. */
export const YTDLP_UPDATE_TIMEOUT_MS = 60_000
/**
 * How long the first-run ffmpeg archive download may STALL (no bytes received)
 * before it's abandoned (ffmpegSetup.ts). Same generous idle budget the app-update
 * download uses; total time is otherwise unbounded (the archive is ~105 MB).
 */
export const FFMPEG_DOWNLOAD_IDLE_TIMEOUT_MS = 60_000
/** Unpacking the two ffmpeg exes with System32 tar.exe — bounded so a wedged extract can't hang setup. */
export const FFMPEG_EXTRACT_TIMEOUT_MS = 120_000
/** Best-effort metadata --print alongside a download (title/uploader/duration). */
export const META_PROBE_TIMEOUT_MS = 30_000
/** Full format/metadata probe (`-J`) for the download bar. */
export const PROBE_TIMEOUT_MS = 60_000
/** Channel/playlist indexing walk — a big channel legitimately takes minutes. */
export const INDEX_TIMEOUT_MS = 180_000
/** RSS feed fetch for a watched source's new-item check. */
export const FEED_FETCH_TIMEOUT_MS = 15_000

/**
 * Idle watchdog for a running download: if a spawned yt-dlp emits no stdout or
 * stderr for this long, treat it as wedged and kill it so the concurrency slot
 * frees (B1). Generous on purpose so a long, output-less post-processing step
 * (e.g. a large ffmpeg merge) isn't mistaken for a stall.
 */
export const STALL_TIMEOUT_MS = 5 * 60_000

// --- execFile maxBuffer sizes (bytes) ---------------------------------------
// yt-dlp JSON for a big channel/format list is large; cap generously so a valid
// response is never truncated (which would look like a parse failure).

/** Metadata --print output (three short fields). */
export const META_MAX_BUFFER = 4 * 1024 * 1024
/** Single-video `-J` probe JSON. */
export const PROBE_MAX_BUFFER = 64 * 1024 * 1024
/** Whole-channel index JSON. */
export const INDEX_MAX_BUFFER = 256 * 1024 * 1024

// --- Misc ------------------------------------------------------------------

/** How much of a failed download's stderr to retain for the error message. */
export const STDERR_TAIL_BYTES = 4000

/**
 * Size cap for the diagnostic log file (logger.ts, CC8). Once the live
 * `aerofetch.log` passes this, it's rotated to `aerofetch.log.1` (one generation
 * kept) so app logging can't fill the disk.
 */
export const LOG_MAX_BYTES = 1024 * 1024

// --- JSON-store row caps ----------------------------------------------------
// Each hand-rolled JSON store trims to its cap on write so a store file can't
// grow without bound.

/** Diagnostics error log (errorlog.json). */
export const ERRORLOG_MAX_ENTRIES = 200
/** Saved custom-command templates (templates.json). */
export const TEMPLATES_MAX = 100
/** Saved media profiles (profiles.json). */
export const PROFILES_MAX = 100
/** Indexed media items across all sources (media-items.json). */
export const MEDIA_ITEMS_MAX = 20_000
/** Persisted download-queue rows (queue.json, M4) — generous; a whole channel can be queued. */
export const QUEUE_MAX = 10_000
