'use strict';

const initialState = {
  lastTicketCapturedAt: null,
  lastTicketParsedAt: null,
  lastQrGeneratedAt: null,
  lastQrPrintedAt: null,
  lastBillingCode: null,
  lastFolio: null,
  lastTotal: null,
  lastQrUrlMasked: null,
  lastQrDecision: null,
  lastQrRender: null,
  lastTicketTokenEvent: null,
  lastTicketTokenValid: null,
  lastQrUrlUsesBranchToken: null,
  lastParseError: null,
  lastPrintError: null,
  lastRawPrintError: null,
  lastOutputPrinterName: null,
  lastPhysicalPrintAt: null,
  lastRawPrintSuccessAt: null,
  lastRawPrintPrinterName: null,
  lastProcessedFile: null,
  lastProcessedAt: null,
  lastCaptureSource: null,
  serviceRuntimeHasBillingPrint: null,
  processPid: null,
  lastCaptureSnapshots: null,
  selectedSnapshotSize: null,
  ignoredSmallJobsCount: 0,
  overwriteProtected: false,
  lastRuntimeContext: null,
  captureCreatedAt: null,
  snapshotSelectedAt: null,
  parsedAt: null,
  qrDecisionAt: null,
  rawPrintStartAt: null,
  rawPrintSuccessAt: null,
  totalMs: null,
  captureToStableMs: null,
  stableToParsedMs: null,
  parsedToDecisionMs: null,
  decisionToRawMs: null,
  rawPrintMs: null,
  totalPipelineMs: null,
  lastPipelineTiming: null,
};

const state = { ...initialState };

function mark(update = {}) {
  Object.assign(state, update);
  return snapshot();
}

function snapshot() {
  return { ...state };
}

function reset() {
  for (const key of Object.keys(state)) state[key] = initialState[key];
}

module.exports = {
  mark,
  snapshot,
  reset,
};
