import 'package:flutter/foundation.dart';
import 'package:http_interceptor/http_interceptor.dart';

class LoggingInterceptor implements InterceptorContract {
  @override
  Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
    debugPrint('----------------------------------------------------');
    debugPrint('REQUEST: ${request.method} ${request.url}');
    debugPrint('Headers: ${request.headers}');
    if (request is Request) {
      debugPrint('Body: ${request.body}');
    }
    debugPrint('----------------------------------------------------');
    return request;
  }

  @override
  Future<BaseResponse> interceptResponse({required BaseResponse response}) async {
    debugPrint('----------------------------------------------------');
    debugPrint('RESPONSE: ${response.statusCode} ${response.request?.url}');
    if (response is Response) {
      debugPrint('Body: ${response.body}');
    }
    debugPrint('----------------------------------------------------');
    return response;
  }

  @override
  Future<bool> shouldInterceptRequest() async => true;

  @override
  Future<bool> shouldInterceptResponse() async => true;
}
