import { COUNTRY_BY_DIAL_CODE_PENDING, COUNTRY_BY_DIAL_CODE_SUCCESS, COUNTRY_BY_DIAL_CODE_ERROR, COUNTRY_BY_DIAL_CODE_RESET } from "../types/CountryNetworkType";

const initialState = {
     loading: false,
     result: null,
     error: null
};

export default (state = initialState, action) => {
     switch (action.type) {
          case COUNTRY_BY_DIAL_CODE_PENDING: return {
               ...state,
               loading: true
          }
          case COUNTRY_BY_DIAL_CODE_SUCCESS: return {
               ...state,
               loading: false,
               result: action.result.data,
               error: null
          }
          case COUNTRY_BY_DIAL_CODE_ERROR: return {
               ...state,
               loading: false,
               result: null,
               error: action.result
          }
          case COUNTRY_BY_DIAL_CODE_RESET: return initialState;

          default: {
               return state;
          }
     }
};
