/**
 * React Native Full App (https://store.enappd.com/product/react-native-full-app)
 *
 * Copyright © 2019-present Enappd. All rights reserved.
 *
 * This source code is licensed as per the terms found in the
 * LICENSE.md file in the root directory of this source tree.
 */
import env from '../../Database/grocery/data'
import { GET_SIMILAR_PRODUCTS, ProductDetialsActionTypes } from "../types/ProductDetailsPage";
import { ThunkAction } from "redux-thunk";
import { AppReduxState } from "../reducers";
import { Action } from "redux";


export function getSimilarProducts(): ThunkAction<void,AppReduxState,null,Action<string>> {
    return (dispatch: any) => {
      fetch('http://5cbf130e06a6810014c6632a.mockapi.io/api/v1/similarProducts')
        .then(response => response.json())
        .then(productData => {
          dispatch(getSimilarProductsDispatch(productData))
        })
        .catch(e => console.error("get error in fetch", e))
    }
  }
  
  function getSimilarProductsDispatch(data: any): ProductDetialsActionTypes {
    return {
      type: GET_SIMILAR_PRODUCTS,
      payload: env.topSaversproduct
    };
  }