import { Type } from '@angular/core';
import { Action, combineReducers, Selector, createSelector } from '@ngrx/store';

import * as AuthenticationStore from './authentication';
import * as InfoStore from './info';

export interface State {
  authentication: AuthenticationStore.State;
  info: InfoStore.State;
}

export const effects: Type<any>[] = [
  AuthenticationStore.Effects,
  InfoStore.Effects
];

export function reducers(state: State | undefined, action: Action) {
  return combineReducers({
    authentication: AuthenticationStore.reducer,
    info: InfoStore.reducer
  })(state, action);
}

export function selectors<S>(selector: Selector<any, State>) {
  return {
    AuthenticationSelector: AuthenticationStore.selectors(
      createSelector(
        selector,
        (state: State) => state.authentication
      )
    ),

    InfoSelector: InfoStore.selectors(
      createSelector(
        selector,
        (state: State) => state.info
      )
    )
  };
}
