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

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

import { Infra } from '@overflow/commons-typescript/model/infra';

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

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

    case ActionType.ReadAllByProbe: {
      return {
        ...state,
        error: null,
        isPending: true,
      };
    }

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

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

    default: {
      return state;
    }
  }
}
