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

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

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

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

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

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

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

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

    default: {
      return state;
    }
  }
}
