import {
  Actions,
  ActionType,
} from './auth.action';

import {
  State,
  initialState,
} from './auth.state';

export function reducer(state: State = initialState, action: Actions): State {
  switch (action.type) {
    case ActionType.SigninSuccess: {
      return {
        signined: true,
        domainMember: action.payload.domainMember,
      };
    }

    case ActionType.SigninCookieSuccess: {
      return {
        signined: true,
        domainMember: action.payload.domainMember,
      };
    }

    case ActionType.SignoutSuccess: {
      return {
        signined: false,
        domainMember: null,
      };
    }

    case ActionType.ModifySuccess: {
      state.domainMember.member = action.payload;
      return {
        ...state,
      };
    }

    default: {
      return state;
    }
  }
}
