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

import * as AuthenticationStore from './authentication';
import * as PrivacyStore from './privacy';

export interface State {
  authentication: AuthenticationStore.State;
  privacy: PrivacyStore.State;
}

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

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

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