import 'package:domain/repository/auth_repository.dart';
import 'package:domain/repository/job_repository.dart';
import 'package:domain/repository/job_sg_repository.dart';
import 'package:domain/repository/labour_repository.dart';
import 'package:domain/repository/labour_sg_repository.dart';
import 'package:domain/repository/ms_repository.dart';
import 'package:domain/repository/other_repository.dart';
import 'package:domain/repository/th_er_repository.dart';
import 'package:domain/repository/th_oa_repository.dart';
import 'package:domain/repository/uk_attendance_repository.dart';
import 'package:domain/repository/uk_job_repository.dart';
import 'package:domain/repository/uk_report_repository.dart';
import 'package:domain/repository/uk_review_repository.dart';
import 'package:domain/repository/sg_agency_repository.dart';
import 'package:plugin_basic/basic_export.dart';
import 'package:plugin_basic/service/http_provider_injection.dart';
import 'package:plugin_basic/service/user_service.dart';
import 'package:shared/utils/log_utils.dart';

/*
   全局服务 Service 的初始化入口

   1. 默认注入网络请求Provider与Domain的Repository
   2. 留下高阶函数的入口，方便加入其他的全局服务

   全局单例服务的注入，在 main.dart 入口就可直接调用，注意手动调用
 */
class GlobalServicesInjection {
  /// init
  static void init({void Function()? additionalDependencies}) {
    Log.d('----ConfigServicesInjection------start-----');

    //全局单例的 HttpProvider 用于发起网络请求 （根据不同的选择国家注入不同的域名）
    HttpProviderInjection.putHttpProviderByCountry();

    //全局单例的用户数据仓库
    Get.put(AuthRepository(httpProvider: Get.find()));

    //全局单例用户信息服务（用户信息相关业务类）
    Get.put(UserService(Get.find()));

    //各模块的数据仓库注入
    Get.lazyPut(() => JobRepository(httpProvider: Get.find()));
    Get.lazyPut(() => JobSGRepository(httpProvider: Get.find()));
    Get.lazyPut(() => LabourRepository(httpProvider: Get.find()));
    Get.lazyPut(() => LabourSGRepository(httpProvider: Get.find()));
    Get.lazyPut(() => OtherRepository(httpProvider: Get.find()));
    Get.lazyPut(() => SGAgencyRepository(httpProvider: Get.find()));

    //UK的数据仓库注入
    Get.lazyPut(() => UKJobRepository(httpProvider: Get.find()));
    Get.lazyPut(() => UKAttendanceRepository(httpProvider: Get.find()));
    Get.lazyPut(() => UKReviewRepository(httpProvider: Get.find()));
    Get.lazyPut(() => UKReportRepository(httpProvider: Get.find()));

    //MS/NL的数据仓库注入
    Get.lazyPut(() => MSRepository(httpProvider: Get.find()));
    Get.lazyPut(() => THERRepository(httpProvider: Get.find()));
    Get.lazyPut(() => THOARepository(httpProvider: Get.find()));

    // 调用额外的依赖注入逻辑（如果提供了）
    if (additionalDependencies != null) {
      additionalDependencies();
    }

    Log.d('----ConfigServicesInjection------end-----');
  }

}
