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

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

import { DiscoveryStartInfo } from '@overflow/commons-typescript/model/discovery';

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

    case ActionType.SettingSuccess: {
      return {
        ...state,
        isStart: true,
        error: null,
        isPending: false,
        discoveryStartInfo: action.payload,
      };
    }

    case ActionType.SettingFailure: {
      return {
        ...state,
        isStart: false,
        error: action.payload,
        isPending: false,
        discoveryStartInfo: null,
      };
    }

    default: {
      return state;
    }
  }
}
