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

    case ActionType.Accept: {
      return {
        ...state,
        pending: true,
      };
    }
    case ActionType.AcceptSuccess: {
      return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false});
    }
    case ActionType.AcceptFailure: {
      return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false});
    }

    case ActionType.Deny: {
      return {
        ...state,
        pending: true,
      };
    }
    case ActionType.DenySuccess: {
      return noAuthProbeListContainerAdapter.setAll(action.payload, {...state, pending: false});
    }
    case ActionType.DenyFailure: {
      return noAuthProbeListContainerAdapter.setError(action.payload, {...state, pending: false});
    }

    default: {
      return state;
    }
  }
}
