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

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

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

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,
        probeHosts: action.payload,
      };
    }

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

    default: {
      return state;
    }
  }
}
