import 'package:dio/dio.dart';
import 'package:injectable/injectable.dart';
import 'package:location/data/api/atmob_api.dart';
import 'package:location/data/api/atmob_stream_api.dart';
import 'package:location/data/consts/constants.dart';
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
import '../data/api/interceptor/stream_dio_log_interceptor.dart';
import '../data/consts/build_config.dart';

@module
abstract class NetworkModule {
  @singleton
  Dio createDefaultDio() {
    Dio dio = Dio(BaseOptions());
    dio.interceptors.add(PrettyDioLogger(
      requestHeader: true,
      requestBody: true,
      responseBody: true,
      responseHeader: false,
      error: true,
      compact: true,
      enabled: BuildConfig.isDebug,
    ));
    return dio;
  }

  @Named('stream')
  @singleton
  Dio createStreamDio() {
    Dio streamDio = Dio(BaseOptions(
      responseType: ResponseType.stream,
    ));
    streamDio.interceptors.add(StreamDioLogInterceptor());
    return streamDio;
  }

  @singleton
  AtmobApi provideAtmobApi(Dio dio) {
    return AtmobApi(dio, baseUrl: Constants.baseUrl);
  }

  @singleton
  AtmobStreamApi provideAtmobStreamApi(@Named('stream') Dio dio) {
    return AtmobStreamApi(dio, baseUrl: Constants.baseUrl);
  }
}
