import axios from "axios"
import {
	// SERVER_URI_PY, 
	SERVER_URI_NJ,  
	CONSTANTS, } from "../constants"

// test action of webSocketData getting
export const startWebSocketAction = () => {
	return (dispatch: {
		(arg0: { type: string }): void,
		(arg0: { type: string, result: any }): void,
		(arg0: { type: string, error: any }): void,
	}) => {
		dispatch({
			type: "LOAD_REQUESTED_DATA_ACTION",
		})
		axios
			.get(`${SERVER_URI_NJ}/additionals/start-screener/`)
			// .get(`${SERVER_URI_NJ}/reports/start-websocket/`)
			// .get(`${SERVER_URI_PY}/start-websocket/`)
			.then(response => {
				// console.log(response.data)
				dispatch({
					type: "START_WS_ACTION",
					result: response.data,
				})
			})
			.catch(error => {
				dispatch({
					type: "LOAD_FAILURE_DATA_ACTION",
					result: {
						error,
						message: `${CONSTANTS.ERROR_REQUEST}/additionals/start-screener/`,
						// message: `${CONSTANTS.ERROR_REQUEST}/reports/start-websocket/`,
					  // message: `${CONSTANTS.ERROR_REQUEST}/start-websocket/`,
					},
				})
				console.log(error)
			})
	}
}

// test action of fundingRates getting
export const getFundingRatesAction = (userId: string) => {
	const params = { userId }
	return (dispatch: {
		(arg0: { type: string }): void,
		(arg0: { type: string, result: any }): void,
		(arg0: { type: string, error: any }): void,
	}) => {
		dispatch({
			type: "LOAD_REQUESTED_DATA_ACTION",
		})
		axios
			.post(`${SERVER_URI_NJ}/reports/get-funding-rates/`, params)
			.then(response => {
				// console.log(response.data)
				dispatch({
					type: "GET_FUNDING_RATES_ACTION",
					result: response.data,
				})
			})
			.catch(error => {
				dispatch({
					type: "LOAD_FAILURE_DATA_ACTION",
					result: {
						error,
						message: `${CONSTANTS.ERROR_REQUEST}/reports/get-funding-rates/`,
					},
				})
				console.log(error)
			})
	}
}