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

import LangFormat from '@caj/lang/default';
import {lang as defaultLang} from '@caj/lang/en';
import {UserId} from './types';
import {MyUserAccount} from '@caj/user/types';

export interface userList {
  myUserList: {[key: UserId]: MyUserAccount};
}

const initialState: userList = {
  myUserList: {},
};

export const usersSlice = createSlice({
  name: 'users',
  initialState,
  reducers: {
    setAccount: (state, action: PayloadAction<MyUserAccount>) => {
      state.myUserList[action.payload.UserId] = action.payload;
    },
  },
});

// Action creators are generated for each case reducer function
const {actions} = usersSlice;
export const usersActions = actions;

export default usersSlice.reducer;
