import { ActionType, Actions } from '../../entity/probe';
import {
  State,
  initialState,
  probeSelectorContainerAdapter
} from './probe-selector.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 probeSelectorContainerAdapter.setAll(action.payload, {...state, pending: false});
    }

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

    default: {
      return state;
    }
  }
}
