import { createReducer, on } from '@ngrx/store';
import { initialState } from './state';
import { authSuccess, deptSuccess, myDeptUserSuccess } from './actions';

import * as AuthenticationStore from '@app/store/account/authentication';

export const reducer = createReducer(
  initialState,
  on(authSuccess, (state, action) => {
    return {
      ...state,
      auth: action.res
    };
  }),

  on(deptSuccess, (state, action) => {
    return {
      ...state,
      departmentInfoList: action.departmentInfoList
    };
  }),

  on(myDeptUserSuccess, (state, action) => {
    return {
      ...state,
      myDepartmentUserInfoList: action.userInfos
    };
  }),

  on(AuthenticationStore.logoutInitialize, (state, action) => {
    return {
      ...initialState
    };
  })
);
