text: import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"
  import { apiService } from "./api"
  export const api_v1_category_list = createAsyncThunk(
    "categories/api_v1_category_list",
    async payload => {
      const response = await apiService.api_v1_category_list(payload)
      return response.data
    }
  )
  export const api_v1_category_create = createAsyncThunk(
    "categories/api_v1_category_create",
    async payload => {
      const response = await apiService.api_v1_category_create(payload)
      return response.data
    }
  )
  export const api_v1_category_read = createAsyncThunk(
    "categories/api_v1_category_read",
    async payload => {
      const response = await apiService.api_v1_category_read(payload)
      return response.data
    }
  )
  export const api_v1_category_update = createAsyncThunk(
    "categories/api_v1_category_update",
    async payload => {
      const response = await apiService.api_v1_category_update(payload)
      return response.data
    }
  )
  export const api_v1_category_partial_update = createAsyncThunk(
    "categories/api_v1_category_partial_update",
    async payload => {
      const response = await apiService.api_v1_category_partial_update(payload)
      return response.data
    }
  )
  export const api_v1_category_delete = createAsyncThunk(
    "categories/api_v1_category_delete",
    async payload => {
      const response = await apiService.api_v1_category_delete(payload)
      return response.data
    }
  )
  const initialState = { entities: [], api: { loading: "idle", error: null } }
  const categoriesSlice = createSlice({
    name: "categories",
    initialState,
    reducers: {},
    extraReducers: {
      [api_v1_category_list.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_list.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities = action.payload
          state.api.loading = "idle"
        }
      },
      [api_v1_category_list.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      },
      [api_v1_category_create.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_create.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities.push(action.payload)
          state.api.loading = "idle"
        }
      },
      [api_v1_category_create.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      },
      [api_v1_category_read.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_read.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities = [
            ...state.entities.filter(record => record.id !== action.payload.id),
            action.payload
          ]
          state.api.loading = "idle"
        }
      },
      [api_v1_category_read.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      },
      [api_v1_category_update.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_update.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities = state.entities.map(record =>
            record.id === action.payload.id ? action.payload : record
          )
          state.api.loading = "idle"
        }
      },
      [api_v1_category_update.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      },
      [api_v1_category_partial_update.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_partial_update.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities = state.entities.map(record =>
            record.id === action.payload.id ? action.payload : record
          )
          state.api.loading = "idle"
        }
      },
      [api_v1_category_partial_update.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      },
      [api_v1_category_delete.pending]: (state, action) => {
        if (state.api.loading === "idle") {
          state.api.loading = "pending"
        }
      },
      [api_v1_category_delete.fulfilled]: (state, action) => {
        if (state.api.loading === "pending") {
          state.entities = state.entities.filter(
            record => record.id !== action.meta.arg?.id
          )
          state.api.loading = "idle"
        }
      },
      [api_v1_category_delete.rejected]: (state, action) => {
        if (state.api.loading === "pending") {
          state.api.error = action.error
          state.api.loading = "idle"
        }
      }
    }
  })
  export default {
    api_v1_category_list,
    api_v1_category_create,
    api_v1_category_read,
    api_v1_category_update,
    api_v1_category_partial_update,
    api_v1_category_delete,
    slice: categoriesSlice
  }
  