import {
  Session, ContextBuilder, EdgeChoiceBuilder, isNodePayload,
  type SessionSnapshot,
} from '@execkernel/sdk';

const original = ContextBuilder.from({ reviewed: false });
const choice = new EdgeChoiceBuilder()
  .withEdgeId(7)
  .withContext(original.with('reviewed', true))
  .toObject();

const session = new Session({
  sessionId: 'reference-session',
  state: { current_node: 4, context: original.toObject() },
  payload: {
    type: 'node', nodeId: 4, title: 'Review the record',
    edges: [{ id: 7, label: 'Confirm' }],
  },
});
const snapshot: SessionSnapshot = session.export();
snapshot.state!.context!.reviewed = true;
const restored = new Session().import(snapshot);

console.log(JSON.stringify({
  choice,
  liveReviewed: session.context!.reviewed,
  importedReviewed: restored.context!.reviewed,
  title: isNodePayload(restored.currentPayload)
    ? restored.currentPayload.title : null,
  snapshot: session.export(),
}, null, 2));
