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

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

export const reducer = createReducer(
  initialState,
  on(versionInfo2Success, (state, action) => {
    return {
      ...state,
      profileImageRoot: action.res.profileRoot,
      profileImageUploadUrl: action.res.profileUploadUrl,
      fileUploadMaxSize:
        !!action.res.fileAllowSize &&
        !isNaN(action.res.fileAllowSize) &&
        0 < action.res.fileAllowSize
          ? action.res.fileAllowSize
          : 0,
      fileUploadUrl: action.res.uploadUrl,
      fileDownloadUrl: action.res.downloadUrl,
      serverIp: action.res.serverIp
    };
  }),

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