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

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

interface UseChildOutgoingInstancesOptions {
  enabled?: boolean;
}

export const useChildOutgoingInstances = (
  outgoingInstanceId: string,
  options?: UseChildOutgoingInstancesOptions,
) => {
  return useQuery<AssignmentHistoryDto[]>({
    queryKey: ["child-outgoing-instances", outgoingInstanceId],

    queryFn: () => getMainChildIncomingInstances(outgoingInstanceId),

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