import { ActionType, Actions } from './meta-sensor-item-unit.action';
import {
  State,
  initialState,
  metaSensorItemUnitEntityAdapter,
} from './meta-sensor-item-unit.state';

export function reducer(state: State = initialState, action: Actions): State {
  switch (action.type) {
    case ActionType.ReadAll: {
      return {
        ...state,
      };
    }
    case ActionType.ReadAllSuccess: {
      return metaSensorItemUnitEntityAdapter.setAll(action.payload, state);
    }
    case ActionType.ReadAllFailure: {
      return metaSensorItemUnitEntityAdapter.setError(action.payload, state);
    }

    default: {
      return state;
    }
  }
}
