import { useQuery } from "@tanstack/react-query";

import { getChildIncomingInstances } from "@/record-management/services/api/incomingInstanceService";
import { AssignmentHistoryDto } from "../userIncoming/remarkCreationCard";

interface UseChildIncomingInstancesOptions {
  enabled?: boolean;
}

export const useChildIncomingInstances = (
  incomingInstanceId: string,
  options?: UseChildIncomingInstancesOptions,
) => {
  return useQuery<AssignmentHistoryDto[]>({
    queryKey: ["child-incoming-instances", incomingInstanceId],

    queryFn: () => getChildIncomingInstances(incomingInstanceId),

    enabled:
      options?.enabled !== undefined
        ? options.enabled && !!incomingInstanceId
        : !!incomingInstanceId,
    staleTime: 0,
  });
};
