// /redux/slices/webservice/userRightsSlice.js
import { createSlice } from "@reduxjs/toolkit";
import { fetchUserRightsThunk } from "../../thunks/webservice/fetchUserRightsThunk";

const initialState = {
  rights: [],
  status: "idle",
  error: null,
};

export const userRightsSlice = createSlice({
  name: "gisUserRightsFromWebservice",
  initialState,
  reducers: {},
  extraReducers: (builder) => {
    builder
      .addCase(fetchUserRightsThunk.pending, (state) => {
        state.status = "loading";
      })
      .addCase(fetchUserRightsThunk.fulfilled, (state, action) => {
        state.status = "succeeded";
        state.rights = action.payload;
      })
      .addCase(fetchUserRightsThunk.rejected, (state, action) => {
        state.status = "failed";
        state.error = action.payload;
      });
  },
});

export default userRightsSlice.reducer;

export const selectGisUserRightsFromWebservice = (state) => state.gisUserRightsFromWebservice.rights;
export const selectGisUserRightsStatus = (state) => state.gisUserRightsFromWebservice.status;
