import 'package:flutter/services.dart';

import '../print/print.dart';
import 'names.dart';

class ChannelManager {
  static Future<void> getCallLog(String param) async {
    MethodChannel channel = MethodChannel(getChannelName(kGetCallLog));
    try {
      final result = await channel.invokeMethod(kGetCallLog, param);
      yjPrint(result);
    } on PlatformException catch (e) {
      yjPrint('$kGetCallLog 发生异常:$e');
    }
  }

  static Future<void> acceptCall() async {
    MethodChannel channel = MethodChannel(getChannelName(kAcceptCall));
    try {
      final result = await channel.invokeMethod(kAcceptCall);
      yjPrint(result);
    } on PlatformException catch (e) {
      yjPrint('$kAcceptCall 发生异常:$e');
    }
  }

  static Future<void> rejectCall() async {
    MethodChannel channel = MethodChannel(getChannelName(kRejectCall));
    try {
      final result = await channel.invokeMethod(kRejectCall);
      yjPrint(result);
    } on PlatformException catch (e) {
      yjPrint('$kRejectCall 发生异常:$e');
    }
  }

  static Future<void> endCall() async {
    MethodChannel channel = MethodChannel(getChannelName(kEndCall));
    try {
      final result = await channel.invokeMethod(kEndCall);
      yjPrint(result);
    } on PlatformException catch (e) {
      yjPrint('$kEndCall 发生异常:$e');
    }
  }
}