import {
  PERMISSIONS_DATA_URL,
  ROLES_DATA_URL,
  SINGED_USER_INFO_URL
} from "utils/constants";
import { RolesType, UserType } from "utils/types/appTypes";
import { baseApi } from "./apiSlice";

export const roleApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    getRoles: builder.query<Array<RolesType>, void>({
      query: () => ROLES_DATA_URL,
      transformResponse: (response: any) => {
        return response.data;
      },
    }),
    getPermissions: builder.query<Array<any>, void>({
      query: () => PERMISSIONS_DATA_URL,
      transformResponse: (response: any) => {
        return response.data;
      },
    }),
    getSignedUserInfo: builder.query<UserType, void>({
      query: () => SINGED_USER_INFO_URL,
    }),
  }),
});
export const {
  useGetRolesQuery,
  useGetPermissionsQuery,
  useGetSignedUserInfoQuery,
} = roleApi;
