import http from '@ohos.net.http';
import libRtsSDK from 'librtssdk.so';
export function OhosHttpRequest(a, b, c, d, e) {
    let f = {
        method: c ? http.RequestMethod.POST : http.RequestMethod.GET
    };
    if (d !== null && d !== undefined) {
        f.header = d;
    }
    if (e !== null && e !== undefined) {
        f.extraData = e;
    }
    console.debug('[ArkTS HttpTool]Request:isPost=' + c.toString() + ',url=' + a);
    let g = http.createHttp();
    g.on('headersReceive', (l) => {
        console.debug('header: ' + JSON.stringify(l));
    });
    g.request(a, f, (h, i) => {
        if (!h && i) {
            let j = (i.result !== null && i.result !== undefined) ? i.result.toString() : '';
            let k = (i.responseCode !== null && i.responseCode !== undefined) ? i.responseCode.toString() : '';
            console.debug('[ArkTS HttpTool] isPost:' + c.toString() + ',url=' + a + ', code=' + k + ', response:' + j);
            libRtsSDK.onHttpResponse(b, k, j);
            g.off('headersReceive');
            g.destroy();
        }
        else {
            console.error('[ArkTS HttpTool] isPost:' + c.toString() + ',url=' + a + 'failed..');
            libRtsSDK.onHttpResponse(b, '701', "httpRequest Syscall Failed");
            g.off('headersReceive');
            g.destroy();
        }
    });
}
export class RtsSDK {
    static RegisterRtsSDK() {
        libRtsSDK.threadsafeRegisterNapiFunc(OhosHttpRequest);
    }
}
