export function createMessageAttemptTracker(randomId = () => crypto.randomUUID()) {
  let pending;
  return {
    begin(payload) {
      const fingerprint = JSON.stringify(payload);
      if (pending?.fingerprint === fingerprint) return pending.id;
      pending = { id: randomId(), fingerprint };
      return pending.id;
    },
    succeeded(id) {
      if (pending?.id === id) pending = undefined;
    },
    failed(id, error) {
      if (pending?.id === id && error?.message !== "pc_unreachable") pending = undefined;
    },
    reset() {
      pending = undefined;
    }
  };
}

export function createNewChatAttempt(randomId = () => crypto.randomUUID()) {
  return {
    clientSessionId: randomId(),
    clientMessageId: randomId(),
    created: null,
    uploadedAttachments: null
  };
}
