import 'package:firebase_messaging/firebase_messaging.dart' show FirebaseMessaging;
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/services/logger_service.dart';

abstract class FirebaseService {
  Future<String?> getDeviceToken();
}

class FirebaseServiceImpl implements FirebaseService {
  final FirebaseMessaging firebaseMessaging;
  final LoggerService loggerService;
  final AppState appState;

  FirebaseServiceImpl({
    required this.firebaseMessaging,
    required this.loggerService,
    required this.appState,
  });

  @override
  Future<String> getDeviceToken() async {
    try {
      String? deviceToken = await firebaseMessaging.getToken();
      appState.setDeviceToken = deviceToken;
      return deviceToken ?? "";
    } catch (e) {
      loggerService.logInfo(e.toString());
      return "";
    }
  }
}
