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

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

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


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

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

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

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

    default: {
      return state;
    }
  }
}
