import { createAsyncThunk } from "@reduxjs/toolkit";
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";
import axios from "axios";
export const provinceGetDashboardKillRequestService = createAsyncThunk(
  "KILL_REQUEST_PROVINCE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());

    const params = {
      date1: d.selectedDate1,
      date2: d.selectedDate2,
      role: getRoleFromUrl(),
      role_key: d.role_key || "",
      filter: "search",
      value: d.textValue,
    };

    if (d.hasDocumentState) {
      params.allocated_car_state = true;
    }

    const { data, status } = await axios.get(
      `dahsnoard_province_kill_request`,
      { params }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceGetDashboardDeletedKillRequestService = createAsyncThunk(
  "DELETED_KILL_REQUEST_PROVINCE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      `dahsnoard_province_kill_request`,
      {
        params: {
          date1: d.selectedDate1,
          date2: d.selectedDate2,
          role: getRoleFromUrl(),
          role_key: d.role_key || "",
          deleted_object: true,
          filter: "search",
          value: d.textValue,
        },
      }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);
