import { useMutation } from "@tanstack/react-query";
import {
  AcceptIncomingRecordPayload,
  ReAssignRecordPayload,
  AssignCCPayload,
} from "@/record-management/dto/userRecords/usersDto";
import {
  acceptRecord,
  reassignRecord,
  assignCCRecord,
  AddRemarkPayload,
  addRemarkService,
} from "@/record-management/services/api/incomingRecordService";

export const useAssignTasks = () => {
  const {
    mutate: assignRecord,
    isPending,
    isError,
    isSuccess,
    data,
    error,
  } = useMutation({
    mutationFn: (body: ReAssignRecordPayload) => reassignRecord(body),
  });
  const {
    mutateAsync: addRemark,
    mutateAsync: addRemarkAsync,
    isPending: isAddingRemark,
    isError: isAddRemarkError,
    isSuccess: isAddRemarkSuccess,
    data: addRemarkData,
    error: addRemarkError,
  } = useMutation({
    mutationFn: (body: AddRemarkPayload) => addRemarkService(body),
  });
  const {
    mutate: acceptIncoming,
    isPending: isAcceptPending,
    isError: isAcceptError,
    isSuccess: isAcceptSuccess,
    data: acceptData,
    error: acceptError,
  } = useMutation({
    mutationFn: (body: AcceptIncomingRecordPayload) => acceptRecord(body),
  });

  const {
    mutate: assignCC,
    isPending: isAssignCCPending,
    isError: isAssignCCError,
    isSuccess: isAssignCCSuccess,
    data: assignCCData,
    error: assignCCError,
  } = useMutation({
    mutationFn: (body: AssignCCPayload) => assignCCRecord(body),
  });

  return {
    assignRecord,
    isPending,
    isError,
    isSuccess,
    data,
    error,
    acceptIncoming,
    isAcceptPending,
    isAcceptError,
    isAcceptSuccess,
    acceptData,
    acceptError,
    assignCC,
    isAssignCCPending,
    isAssignCCError,
    isAssignCCSuccess,
    assignCCData,
    assignCCError,
    addRemark,
    addRemarkAsync,
    isAddRemarkError,
    isAddingRemark,
  };
};
