import { useMutation } from "@tanstack/react-query";
import {
  createAndAssignNonSmartRecordPdf,
  updateAndAssignNonSmartRecordPdf,
} from "@/record-management/services/api/nonSmartOfficeService";
import { NonSmartRecordPdfAssignPayload } from "@/record-management/dto/IncomingRecords/nonSmartRecordPdfDto";

export const useNonSmartRecordPdfAssign = () => {
  const {
    mutateAsync: createAndAssign,
    isPending: isCreating,
    isSuccess: isCreateSuccess,
    data: createData,
    error: createError,
    reset: resetCreate,
  } = useMutation({
    mutationFn: (payload: NonSmartRecordPdfAssignPayload): Promise<any> =>
      createAndAssignNonSmartRecordPdf(payload),
  });

  const {
    mutateAsync: updateAndAssign,
    isPending: isUpdating,
    isSuccess: isUpdateSuccess,
    data: updateData,
    error: updateError,
    reset: resetUpdate,
  } = useMutation({
    mutationFn: ({ id, payload }: { id: string; payload: NonSmartRecordPdfAssignPayload }): Promise<any> =>
      updateAndAssignNonSmartRecordPdf(id, payload),
  });

  return {
    createAndAssign,
    isCreating,
    isCreateSuccess,
    createData,
    createError,
    resetCreate,
    updateAndAssign,
    isUpdating,
    isUpdateSuccess,
    updateData,
    updateError,
    resetUpdate,
  };
};
