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 provincePolicyEditTradeTimeRange = createAsyncThunk(
  "PROVINCE_POLICY_EDIT_TRADE_TIME_RANGE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.put("show-market-requests/0/", d);
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const provincePolicyGetTradeTimeRagnge = createAsyncThunk(
  "PROVINCE_POLICY_GET_TRADE_TIME_RANGE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get("show-market-requests", {
      params: {
        role: getRoleFromUrl(),
      },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);
