import {
  errorRecord,
  firebaseAttributes,
} from "./libEventLog/libCrashlytics/libCrashlyticsEvent";
import Database from "../../../../Components/common/DAsyncStorage";

export const clearRedux = (dispatch) => {
  try {
    dispatch({
      type: "CLEAR_ACTIVITY_DATA",
    });
    dispatch({
      type: "CLEAR_IMAGE_CLICKED_COUNT_REDUX",
    });
    dispatch({
      type: "CLEAR_LAST_DATA_REDUX",
    });
    dispatch({
      type: "CLEAR_SENSOR_DETAILS_REDUX",
    });
    dispatch({
      type: "CLEAR_UPLOAD_IMAGE_REDUX",
    });
    dispatch({
      type: "CLEAR_UPLOAD_IMAGE_DATA_REDUX",
    });
    dispatch({
      type: "CLEAR_VEHICLE_DETAILS_REDUX",
    });
    dispatch({
      type: "CLEAR_RETRY_COUNT_REDUX",
    });
    dispatch({
      type: "CLEAR_RETRY_IMAGE_STATE",
    });
    dispatch({
      type: "CLEAR_RCB_DATA",
    });
    dispatch({
      type: "CLEAR_FAILED_DATA",
    });
    dispatch({
      type: "CLEAR_UPLOADING_DATA",
    });
    dispatch({
      type: "CLEAR_COMMON_FLAGS",
    });
  } catch (error) {
    firebaseAttributes(error);
    errorRecord(error);
  }
};

export const clearAllRealmData = async () => {
  try {
    await Database.remove("PIOfflineData");
    await Database.remove("PIVechicleInstruction");
    await Database.remove("PIOfflineVechicleData");
    await Database.update("PIRetryCount", {
      retryCount: 0,
      index: 0,
      isAddNewImageData: false,
    });
    await Database.remove("PILocation");
    await Database.update("PIStartOver", {
      isStartOver: true,
    });
    await Database.update("PIINDEX", {
      lastIndex: 0,
    });
    await Database.update("PIclickedCount", {
      clickedCount: 0,
    });
    await Database.update("PIUploadedCount", {
      uploadedCount: 0,
    });
    await Database.remove("PIVideoCompleteStatus");

    await Database.update("PIDeeplink", {
      isFromLink: false,
    });
    await Database.remove("PIOnProgress");
    await Database.remove("PISuccessFlag");
    await Database.remove("PIReUploadFailed");
    // await Database.remove("PIMediaStatus");
    await Database.remove("PIShouldCreateActivity");
  } catch (error) {
    errorRecord(error);
    firebaseAttributes(error);
  }
};
