import { ActionType, Actions } from '../../entity/probe';
import {
  State,
  initialState,
  probeListContainerAdapter
} from './probe-list.state';

import { Probe } from '@overflow/commons-typescript/model/probe';

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

    case ActionType.ReadAllByDomainIDSuccess: {
      return probeListContainerAdapter.setAll(action.payload, {...state, pending: false});
    }

    case ActionType.ReadAllByDomainIDFailure: {
      return probeListContainerAdapter.setError(action.payload, {...state, pending: false});
    }

    default: {
      return state;
    }
  }
}
