import {
  ActionType,
  Actions,
} from './noauth-probe.action';

import {
  State,
  initialState,
  noAuthProbeAdapter,
} from './noauth-probe.state';

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

    case ActionType.ReadAllByDomainIDSuccess: {
      return noAuthProbeAdapter.setAll(action.payload, state);
    }

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

    case ActionType.Accept: {
      return {
        ...state,
        error: null,
      };
    }

    case ActionType.AcceptSuccess: {
      return noAuthProbeAdapter.setAll(action.payload, state);
    }

    case ActionType.AcceptFailure: {
      return noAuthProbeAdapter.setError(action.payload, state);
    }

    case ActionType.Deny: {
      return {
        ...state,
        error: null,
      };
    }

    case ActionType.DenySuccess: {
      return noAuthProbeAdapter.setAll(action.payload, state);
    }

    case ActionType.DenyFailure: {
      return noAuthProbeAdapter.setError(action.payload, state);
    }
    case ActionType.OnConnect: {

      return {
        ...state,
      };
    }
    case ActionType.OnDisconnect: {
      return {
        ...state,
      };
    }
    default: {
      return state;
    }
  }
}
