import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import { LOADING_END, LOADING_START } from "../../../lib/redux/slices/appSlice";
import { getRoleFromUrl } from "../../../utils/getRoleFromUrl";

export const provinceGetDispenserKillhousesService = createAsyncThunk(
  "PROVINCE_GET_DISPENSER_KILLHOUSES_SERVICE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      `kill-house-warehouse-dashboard-for-province`,
      {
        params: {
          role: getRoleFromUrl(),
          date1: d.selectedDate1 ? d.selectedDate1 : null,
          date2: d.selectedDate2 ? d.selectedDate2 : null,
        },
      }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provinceGetDispenserKillhousesDashboardService = createAsyncThunk(
  "PROVINCE_GET_DISPENSER_KILLHOUSES_DASHBOARD_SERVICE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(
      `total-kill-house-warehouse-dashboard-for-province`,
      {
        params: {
          role: getRoleFromUrl(),
          date1: d.selectedDate1 ? d.selectedDate1 : null,
          date2: d.selectedDate2 ? d.selectedDate2 : null,
        },
      }
    );
    dispatch(LOADING_END());
    return { data, status };
  }
);
