// store/Slice/followSlice.ts

import { createSlice, PayloadAction } from "@reduxjs/toolkit";

interface FollowState {
  followedUsers: { [key: string]: boolean };
}

const initialState: FollowState = {
  followedUsers: {},
};

const followSlice = createSlice({
  name: "follow",
  initialState,
  reducers: {
    setFollowedUsers: (state, action: PayloadAction<{ [key: string]: boolean }>) => {
      state.followedUsers = action.payload;
    },
    toggleFollow: (state, action: PayloadAction<string>) => {
      const userId = action.payload;
      state.followedUsers[userId] = !state.followedUsers[userId];
    },
  },
});

export const { setFollowedUsers, toggleFollow } = followSlice.actions;
export default followSlice.reducer;