'use strict';

const DEFAULT_SNAPSHOT_SCROLLBACK_ROWS = 300;
const MAX_SNAPSHOT_SCROLLBACK_ROWS = 10000;
const SNAPSHOT_SCROLLBACK_ROW_OPTIONS = Object.freeze([0, 100, 300, 1000, 2000, 10000]);

function normalizeSnapshotScrollbackRows(value, fallback = DEFAULT_SNAPSHOT_SCROLLBACK_ROWS) {
  if (value == null || value === '') return normalizeSnapshotScrollbackRows(fallback, DEFAULT_SNAPSHOT_SCROLLBACK_ROWS);
  const n = Number(value);
  if (!Number.isFinite(n)) return normalizeSnapshotScrollbackRows(fallback, DEFAULT_SNAPSHOT_SCROLLBACK_ROWS);
  return Math.max(0, Math.min(MAX_SNAPSHOT_SCROLLBACK_ROWS, Math.floor(n)));
}

module.exports = {
  DEFAULT_SNAPSHOT_SCROLLBACK_ROWS,
  MAX_SNAPSHOT_SCROLLBACK_ROWS,
  SNAPSHOT_SCROLLBACK_ROW_OPTIONS,
  normalizeSnapshotScrollbackRows,
};
