import { createSlice } from '@reduxjs/toolkit';

const initialState = {
  isAuthenticated: false,
  user: null
};

const loginUserSlice = createSlice({
  name: 'loginUser',
  initialState,
  reducers: {
    setLoginUser(state, action) {
      state.isAuthenticated = true;
      state.user = action.payload;
    },

    updateUserFcmToken(state, action) {
      if (state.user) {
        state.user.userfcmtoken = action.payload;
      }
    },

    logoutUser() {
      return initialState; // 🔥 clears entire slice
    }
  }
});

export const { setLoginUser, updateUserFcmToken, logoutUser } = loginUserSlice.actions;

export default loginUserSlice.reducer;
