import {XHttpClient} from "../../http/client"
import {deepClone} from "../../core/collections";

const client = new XHttpClient('http://httpbin.org',
    {ratePerMinute: 60, timeout: 100,
    defaultHeaders: {
        '901230123jsadlمکشسی1': 'asdaw'
    },
    defaultParams: {
        '901230123jsadlمکشسی1': 'asdaw'
    }});

client.interceptors.response.use(function (ajax) {
    ajax.rs.touched = true;
    return ajax;
});

;(async ()=>{
    try {
        let get_params = {
            params: {user_id: 'user1', limit: 10, start: 11},
            headers: {
                'X-Custom-Header': 'some value',
                Authorization: 'Bearer TOKENTOKENTOKENTOKENTOKEN'
            }
        };
        let post_params = {
            params: { user_id: 'user1', limit: 10, start: 11 },
            headers: {
                'X-Custom-Header': 'custom header',
                Authorization: 'Bearer TOKENTOKENTOKENTOKENTOKEN'
            },
            content: {
                type: 'json',
                data:{ category: 'posts', post: {id: 123, text: 'some text'}}
            }
        };
        let ajax;
        for (let i=0;i<3;i++) {
            // Send GET request to http://httpbin.org/get
            // ajax = client.get('get', get_params).then((a)=>console.log(a)).catch((e)=>{console.error(e)})
            ajax = await client.get('get', get_params).then((a, e)=>a).catch((a, e)=>a);
            console.log(ajax,1)
            // Send POST request to http://httpbin.org/post
            ajax = await client.post('post', post_params).then((a, e)=>a).catch((a, e)=>(a));
            console.log(ajax, 2)
        }
    } catch (e) {
        console.error('EX',e)
    }

})()