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

import * as InitStore from './init';
import * as VersionInfoStore from './version-info';

export interface State {
  init: InitStore.State;
  versionInfo: VersionInfoStore.State;
}

export const effects: Type<any>[] = [VersionInfoStore.Effects];

export function reducers(state: State | undefined, action: Action) {
  return combineReducers({
    init: InitStore.reducer,
    versionInfo: VersionInfoStore.reducer
  })(state, action);
}

export function selectors<S>(selector: Selector<any, State>) {
  return {
    InitSelector: InitStore.selectors(
      createSelector(
        selector,
        (state: State) => state.init
      )
    ),
    VersionInfoSelector: VersionInfoStore.selectors(
      createSelector(
        selector,
        (state: State) => state.versionInfo
      )
    )
  };
}
