import 'package:baseproject/core/common/custom_interceptor.dart';
import 'package:baseproject/core/components/alice.dart';
import 'package:baseproject/core/constants/index.dart';
import 'package:baseproject/features/presentation/app/view/app.dart';
import 'package:baseproject/features/repositories/hra_repository.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:get_it/get_it.dart';
import 'package:injectable/injectable.dart';

import 'injection.config.dart';

final GetIt getItSuper = GetIt.instance;

@injectableInit
void configureInjection() {
  // Khởi tạo các dependency được generate bởi injectable
  $initGetIt(getItSuper);

  // Khởi tạo Dio với CustomInterceptor + Alice
  final dio = Dio()
    ..interceptors.addAll(
      kDebugMode
          ? <Interceptor>[
              CustomInterceptor(),
              CustomAlice.setAndGetAlice(navigatorKey).getDioInterceptor(),
            ]
          : <Interceptor>[
              CustomInterceptor(),
            ],
    )
    ..options = BaseOptions(
      baseUrl: kDebugMode ? ApiPath.hra : ApiPathRelease.hra,
      receiveTimeout: 10000,
      connectTimeout: 10000,
      sendTimeout: 10000,
    );

  getItSuper.registerSingleton<Dio>(dio);

  getItSuper.registerSingleton<HraRepository>(
    HraRepository(
      dio,
      baseUrl: kDebugMode ? ApiPath.hra : ApiPathRelease.hra,
    ),
  );
}
