// import {APPTYPE} from '@/utils';
import axios from 'axios';
import { getMid } from '@/utils/';
import { getStorageData } from '../storage';
import { REACT_APP_FETCH_EXTENSION_API_HOST } from '@env';

console.log('REACT_APP_FETCH_HOST==', REACT_APP_FETCH_EXTENSION_API_HOST);
const instance = axios.create({
	baseURL: REACT_APP_FETCH_EXTENSION_API_HOST,
	timeout: 240000,
	headers: {
		'content-type': 'application/json',
		Accept: 'application/json',
	},
});

instance.interceptors.response.use(
	res => {
		return res.data;
	},
	function (err) {
		return Promise.reject(err);
	},
);

export const postRequest = async (url: any, params = {}, config = null) => {
	const mid = await getMid();
	const userInfo = await getStorageData('userInfo');
	const myConfig = {};
	if (config) {
		Object.assign(myConfig, config);
	}
	params = Object.assign(
		{
			baseInfo: {
				mid: mid,
				machineCode: mid,
				loginUid: userInfo?.uid || '',
				token: userInfo?.accessToken || '',
				appType: 3,
			},
		},
		params,
	);

	return instance
		.post(url, params, myConfig)
		.then(res => {
			return res;
		})
		.catch(err => {
			return err;
		});
};
