// /redux/slices/database/area/updateAreaSlice.js

import { createSlice } from "@reduxjs/toolkit";
import { updateAreaThunk } from "../../../thunks/database/area/updateAreaThunk";

const updateAreaSlice = createSlice({
  name: "updateArea",
  initialState: {
    status: "idle",
    error: null,
  },
  reducers: {
    resetUpdateAreaStatus: (state) => {
      state.status = "idle";
      state.error = null;
    },
  },
  extraReducers: (builder) => {
    builder
      .addCase(updateAreaThunk.pending, (state) => {
        state.status = "loading";
      })
      .addCase(updateAreaThunk.fulfilled, (state) => {
        state.status = "succeeded";
      })
      .addCase(updateAreaThunk.rejected, (state, action) => {
        state.status = "failed";
        state.error = action.error.message;
      });
  },
});

export const { resetUpdateAreaStatus } = updateAreaSlice.actions;
export default updateAreaSlice.reducer;
