import {
  ReadAllByDomain,
  ReadAllByDomainFailure,
  ReadAllByDomainSuccess,
  ActionType,
  Actions,
} from './list.action';

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

import { Probe } from '../../model';

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

    case ActionType.ReadAllByDomainSuccess: {
      return {
        ...state,
        error: null,
        isPending: false,
        probes: action.payload,
      };
    }

    case ActionType.ReadAllByDomainFailure: {
      return {
        ...state,
        error: action.payload,
        isPending: false,
        probes: null,
      };
    }

    default: {
      return state;
    }
  }
}
