export interface SessionMeta {
  paneId: string;
  sessionId: string;
  projectPath: string;
  title?: string;
  createdAt: Date;
  lastActivityAt: Date;
}

const sessions = new Map<string, SessionMeta>();

export function register(
  sessionId: string,
  paneId: string,
  projectPath: string,
  title?: string,
): void {
  const now = new Date();
  const existing = sessions.get(paneId);
  if (existing) {
    existing.lastActivityAt = now;
    return;
  }
  sessions.set(paneId, {
    paneId,
    sessionId,
    projectPath,
    title,
    createdAt: now,
    lastActivityAt: now,
  });
}

export function unregister(paneId: string): void {
  sessions.delete(paneId);
}

export function list(): SessionMeta[] {
  return Array.from(sessions.values());
}

export function get(paneId: string): SessionMeta | undefined {
  return sessions.get(paneId);
}
