import 'dart:collection';
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;

class HttpUtil {
  static HttpClient httpClient = HttpClient();
  static HashMap<String,String> headers;

  static String scheme = "http";
  static String host = "api-docker.naiterui.com/";
  static String global_config = "ad/doctorInfo/globalConfig";

  static Future<http.Response> get(String path,{Map<String, dynamic> queryParameters}) async {

    var response = await http.get(Uri(host: "http://$host/$path"));
    // _get(path, host: HttpUtil.host, queryParameters: queryParameters);
    return response;
  }

  static _get(
    String path, {
    String host,
    Map<String, dynamic> queryParameters,
  }) async {
    Uri uri = Uri(
        scheme: scheme,
        host: host,
        path: path,
        queryParameters: queryParameters);

    HttpClientRequest request = await httpClient.getUrl(uri);

    addHeaders(request);

    print('http url---> $uri \n headers---> \n ${request.headers} queryParameters ---> ${uri.queryParameters}');

    HttpClientResponse response = await request.close();

    String responseBody = await response.transform(Utf8Decoder()).join();

    print('http responseBody ---> \n $responseBody');
  }

  static void addHeaders(HttpClientRequest request) {
    request.headers.add("_p", "0");
    request.headers.add("_o", "1");
    request.headers.add("_n", "1");
    request.headers.add("_v", "1.0.0");
    request.headers.add("_nv", "1.0.0");
  }

  post() {}

  postBody() {}
}
