export type ClassifyEntry = {
  id: string;
  docType: string;
  status: "queued" | "uploading" | "done" | "error";
};

export function applyBulkDocType<T extends ClassifyEntry>(
  entries: T[],
  selectedIds: Set<string>,
  docType: string,
): T[] {
  return entries.map((e) =>
    selectedIds.has(e.id) && e.status === "done" ? { ...e, docType } : e,
  );
}

export function selectAllUnclassified(entries: ClassifyEntry[]): Set<string> {
  return new Set(
    entries.filter((e) => e.status === "done" && e.docType === "").map((e) => e.id),
  );
}

export function getClassifiedCount(entries: ClassifyEntry[]): number {
  return entries.filter((e) => e.status === "done" && e.docType !== "").length;
}

export function getUnclassifiedIds(entries: ClassifyEntry[]): string[] {
  return entries.filter((e) => e.status === "done" && e.docType === "").map((e) => e.id);
}

export function uploadedCountForType(uploadedDocs: string[], docType: string): number {
  return uploadedDocs.filter((d) => d === docType).length;
}
