// /redux/slices/database/gisLinesSlice.js
import { createSlice } from "@reduxjs/toolkit";
import { fetchGisLinesThunk } from "../../thunks/database/fetchGisLinesThunk";

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

export default gisLinesSlice.reducer;
export const selectGisLines = (state) => state.gisLines.data;
