// Per-chat session state for DCP.
// Tracks last transform timestamp and message count to avoid re-processing.

interface ChatDcpState {
  lastTransformAt: number;
  lastMessageCount: number;
}

const chatStates = new Map<string, ChatDcpState>();

export function getDcpState(chatId: string): ChatDcpState | undefined {
  return chatStates.get(chatId);
}

export function setDcpState(chatId: string, messageCount: number): void {
  chatStates.set(chatId, { lastTransformAt: Date.now(), lastMessageCount: messageCount });
}

export function clearDcpState(chatId: string): void {
  chatStates.delete(chatId);
}

export function shouldTransform(chatId: string, messageCount: number): boolean {
  const state = chatStates.get(chatId);
  if (!state) return true;
  return state.lastMessageCount !== messageCount;
}
