import 'package:flutter/services.dart';

import '../../application/application.dart';

final class MethodChannelSessionNotificationGateway
    implements SessionNotificationGateway {
  const MethodChannelSessionNotificationGateway({
    MethodChannel methodChannel = const MethodChannel(_methodChannelName),
  }) : _methodChannel = methodChannel;

  static const _methodChannelName = 'gametime.session_notification/methods';

  final MethodChannel _methodChannel;

  @override
  Future<void> show(SessionNotificationContent content) {
    return _invokeIgnoringMissingPlugin('show', content.toJson());
  }

  @override
  Future<void> clear() {
    return _invokeIgnoringMissingPlugin('clear');
  }

  Future<void> _invokeIgnoringMissingPlugin(
    String method, [
    Object? arguments,
  ]) {
    return _methodChannel
        .invokeMethod<void>(method, arguments)
        .onError<MissingPluginException>((_, _) {});
  }
}
