import 'dart:async';

import 'package:get_it/get_it.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/enums/dev_mode.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/core/flavors/flavor.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/data/data_sources/local/counter_data_source_impl.dart';
import 'package:{{#snakeCase}}{{project_name}}{{/snakeCase}}/domain/data_sources/local/counter_data_source.dart';

final getIt = GetIt.I;

/// Service and Data Source locator
abstract class GetItInitializer {
  static FutureOr<void> _initCommon() async {
    // Initialize common sources/services
    getIt.registerLazySingleton<CounterDataSource>(
      CounterDataSourceImpl.new,
    );
  }

  static FutureOr<void> _initMocks() async {
    // Initialize mocked sources/services.
  }

  static FutureOr<void> _initReal() async {
    // Initialize real sources/services
  }

  static FutureOr<void> init() async {
    await _initCommon();
    final flavor = Flavor.get();

    if (flavor.devMode == DevMode.mock) {
      await _initMocks();
    } else {
      await _initReal();
    }

    await getIt.allReady();
  }
}
