import 'dart:convert';

import 'package:doctor_app_flutter/config/shared_pref_kay.dart';
import 'package:doctor_app_flutter/providers/auth_provider.dart';
import 'package:doctor_app_flutter/util/dr_app_shared_pref.dart';
import 'package:http/http.dart';
import 'package:http_interceptor/http_interceptor.dart';

import '../providers/auth_provider.dart';
import '../util/dr_app_shared_pref.dart';

DrAppSharedPreferances sharedPref = new DrAppSharedPreferances();
List<String> publicUrls = [
  LOGIN_URL,
  SELECT_DEVICE_IMEI,
  MEMBER_CHECK_ACTIVATION_CODE_NEW,
  SEND_ACTIVATION_CODE_BY_OTP_NOTIFICATION_TYPE
];

class HttpInterceptor extends InterceptorContract {

  Client getClient(){
  return HttpClientWithInterceptor.build(interceptors: [this]);
}

  Future<RequestData> interceptRequest({RequestData data}) async {
    print('RequestData ${data.body}');
    print('RequestData ${data.url}');
    try {
      data.headers["Content-Type"] = "application/json";
      data.headers["Accept"] = "application/json";
    //   if (publicUrls.contains(data.url)) {
    //     var loggedUserInfo = await sharedPref.getObj('loggedUser');
    //     var token = await sharedPref.getString(TOKEN);
    //     // print("token"+token);
    //     // print('loggedUserInfo${loggedUserInfo["LogInTokenID"]}');
    //     // // the sevices handel the token in differat name so I ask to be change
    //     // // we must change the imple
    //     var body = json.decode(data.body);
    //     body['LogInTokenID']=token;
    //     data.body = json.encode(body);
   
    //     //  data.body['LogInTokenID'] = '';
    //   } else {
    //     if (data.body['LogInTokenID']) {
    //       data.body['LogInTokenID'] = '';
    //     }
    //     if (data.body['TokenID']) {
    //       data.body['TokenID'] = '';
    //     }
    //   }
    } catch (e) {
      print(e);
    }

    // print('data.body${data.body}');
    return data;
  }

  @override
  Future<ResponseData> interceptResponse({ResponseData data}) async {
    // print('ResponseData ${data.body}');
    return data;
  }
}
