import {
  createSelector,
  createFeatureSelector,
} 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';
import * as ModifyStore from './modify';
import * as ResetPasswordStore from './reset-password';

export interface State {
  auth: AuthStore.State;
  signup: SignupStore.State;
  totp: TotpStore.State;
  modify: ModifyStore.State;
  resetPassword: ResetPasswordStore.State;
}

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

export const EFFECTS = [
  AuthStore.Effects,
  SignupStore.Effects,
  TotpStore.Effects,
  ModifyStore.Effects,
  ResetPasswordStore.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.State>(createSelector(
  selectMemberState,
  (state: State) => state.signup
));

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

export const ModifySelector = new StateSelector<ModifyStore.State>(createSelector(
  selectMemberState,
  (state: State) => state.modify
));

export const ResetPasswordSelector = new StateSelector<ResetPasswordStore.State>(createSelector(
  selectMemberState,
  (state: State) => state.resetPassword
));

