import { v4 as uuidv4, v7 as uuidv7 } from 'uuid';

const ENTRY_ID_PREFIX = 'entry_';
const ENTRY_ID_LENGTH = 12;

export function createSessionTreeSessionId(): string {
  return uuidv7();
}

export function createSessionTreeEntryId(existingIds?: { has(id: string): boolean }): string {
  while (true) {
    const id = `${ENTRY_ID_PREFIX}${uuidv4().replace(/-/g, '').slice(0, ENTRY_ID_LENGTH)}`;
    if (!existingIds?.has(id)) {
      return id;
    }
  }
}
