import {
  Actions,
  ActionType,
} from './reset-password.action';

import {
  State,
  initialState,
} from './reset-password.state';

export function reducer(state = initialState, action: Actions): State {
  switch (action.type) {
    case ActionType.ResetPassword: {
      return {
        ...state,
        error: null,
        pending: true,
      };
    }

    case ActionType.ResetPasswordSuccess: {
      return {
        ...state,
        error: null,
        pending: false,
        member: action.payload,
      };
    }

    case ActionType.ResetPasswordFailure: {
      return {
        ...state,
        error: action.payload,
        pending: false,
        member: null,
      };
    }

    case ActionType.ModifyPassword: {
      return {
        ...state,
        error: null,
        pending: true,
      };
    }

    case ActionType.ModifyPasswordSuccess: {
      return {
        ...state,
        error: null,
        pending: false,
        member: action.payload,
      };
    }

    case ActionType.ModifyPasswordFailure: {
      return {
        ...state,
        error: action.payload,
        pending: false,
        member: null,
      };
    }

    default: {
      return state;
    }
  }
}

