// /redux/slices/webService/gisStationsMeasurementsSlice.js

import { createSlice } from "@reduxjs/toolkit";
import { fetchGisStationsMeasurementsThunk } from "../../thunks/webservice/fetchGisStationsMeasurementsThunk";

const slice = createSlice({
  name: "gisStationsMeasurements",
  initialState: {
    data: [],
    status: "idle",
    error: null,
  },
  reducers: {},
  extraReducers: (builder) => {
    builder
      .addCase(fetchGisStationsMeasurementsThunk.pending, (state) => {
        state.status = "loading";
      })
      .addCase(fetchGisStationsMeasurementsThunk.fulfilled, (state, action) => {
        state.status = "succeeded";
        state.data = action.payload;
      })
      .addCase(fetchGisStationsMeasurementsThunk.rejected, (state, action) => {
        state.status = "failed";
        state.error = action.error.message;
      });
  },
});

export default slice.reducer;
export const selectGisStationsMeasurements = (state) => state.gisStationsMeasurements.data;
