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

export const getTicketPermission = createAsyncThunk(
  "GET_TICKET_PERMISSION",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());
    const { data, status } = await axios.get(`ticket-permission/`, {
      params: {
        role: d.role,
      },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);

export const getTicketUsersFromRole = createAsyncThunk(
  "GET_TICKET_USERS_FROM_ROLE",
  async (d, { dispatch }) => {
    dispatch(LOADING_START());

    const roles = Array.isArray(d.role) ? d.role.join(",") : d.role;

    const { data, status } = await axios.get(`get-user-from-role/`, {
      params: {
        role: roles,
      },
    });
    dispatch(LOADING_END());
    return { data, status };
  }
);
