import {
  createSelector,
  createFeatureSelector,
  ActionReducerMap,
  Selector,
} from '@ngrx/store';

import { StateSelector } from 'packages/core/ngrx/store';

import { MODULE } from '../member.constant';

import * as AuthStore from './auth';
import * as SignupStore from './signup';
import * as TotpStore from './totp';

export interface State {
  auth: AuthStore.State;
  signup: SignupStore.Signup;
  totp: TotpStore.State;
}

export const REDUCERS = {
  auth: AuthStore.reducer,
  signup: SignupStore.reducer,
  totp: TotpStore.reducer,
};

export const EFFECTS = [
  AuthStore.Effects,
  SignupStore.Effects,
  TotpStore.Effects,
];

export const selectMemberState = createFeatureSelector<State>(MODULE.name);

export const AuthSelector = new StateSelector<AuthStore.State>(createSelector(
  selectMemberState,
  (state: State) => state.auth
));

export const SignupSelector = new StateSelector<SignupStore.Signup>(createSelector(
  selectMemberState,
  (state: State) => state.signup
));

export const TotpSelector = new StateSelector<TotpStore.State>(createSelector(
  selectMemberState,
  (state: State) => state.totp
));
