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

export interface UserState {
  userInfo?: {
    name?: string;
    avatar?: string;
    job?: string;
    organization?: string;
    location?: string;
    email?: string;
    permissions: Record<string, string[]>;
  };
  userLoading?: boolean;
}

const initialState: UserState = {
  userInfo: {
    permissions: {}
  },
  userLoading: false
};

const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    updateUserInfo(state, action) {
      state.userInfo = action.payload.userInfo || initialState.userInfo;
      state.userLoading = action.payload.userLoading;
    }
  }
});

export const { updateUserInfo } = userSlice.actions;

export default userSlice.reducer;
