import { CAUTION_CREDIT_DEMAND_AGENT_PENDING, CAUTION_CREDIT_DEMAND_AGENT_SUCCESS, CAUTION_CREDIT_DEMAND_AGENT_ERROR, CAUTION_CREDIT_DEMAND_AGENT_RESET } from "../types/NanoCreditType";

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

export default (state = initialState, action) => {
     switch (action.type) {
          case CAUTION_CREDIT_DEMAND_AGENT_PENDING: return {
               ...state,
               loading: true
          }
          case CAUTION_CREDIT_DEMAND_AGENT_SUCCESS: return {
               ...state,
               loading: false,
               result: action.result.data,
               error: null
          }
          case CAUTION_CREDIT_DEMAND_AGENT_ERROR: return {
               ...state,
               loading: false,
               result: null,
               error: action.result
          }
          case CAUTION_CREDIT_DEMAND_AGENT_RESET: return initialState;

          default: {
               return state;
          }
     }
};
