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

class LoggingInterceptor extends Interceptor {
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    if (kDebugMode) {
      print('--- API REQUEST ---');
      print('METHOD: ${options.method}');
      print('URL: ${options.uri}');
      print('HEADERS: ${options.headers}');
      print('BODY: ${options.data}');
      print('-------------------');
    }
    super.onRequest(options, handler);
  }

  @override
  void onResponse(Response response, ResponseInterceptorHandler handler) {
    if (kDebugMode) {
      print('--- API RESPONSE ---');
      print('STATUS_CODE: ${response.statusCode}');
      print('URL: ${response.requestOptions.uri}');
      print('DATA: ${response.data}');
      print('--------------------');
    }
    super.onResponse(response, handler);
  }

  @override
  void onError(DioException err, ErrorInterceptorHandler handler) {
    if (kDebugMode) {
      print('--- API ERROR ---');
      print('STATUS_CODE: ${err.response?.statusCode}');
      print('URL: ${err.requestOptions.uri}');
      print('ERROR: ${err.error}');
      print('RESPONSE_DATA: ${err.response?.data}');
      print('-----------------');
    }
    super.onError(err, handler);
  }
}