
import 'dart:convert';

import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/models/livecare/session_status_model.dart';
import 'package:flutter/services.dart';

class VideoChannel{
  /// channel name
  static const _channel = const MethodChannel("Dr.cloudSolution/videoCall");
  static  openVideoCallScreen(
      {kApiKey, kSessionId, kToken, callDuration, warningDuration, Function() onCallEnd , Function(SessionStatusModel sessionStatusModel) callNotRespond ,Function(String error) onFailure}) async {
    var result;
    try {
      result = await _channel.invokeMethod(
        'openVideoCall',
        {
          "kApiKey": kApiKey,
          "kSessionId": kSessionId,
          "kToken": kToken,
          "appLang": "en",
          "baseUrl": BASE_URL,
          "VC_ID": 3245,
          "TokenID": "hfkjshdf347r8743",
          "generalId": 'Cs2020@2016\$2958',
          "DoctorId": 1485 ,
        },
      );
      if(result['callResponse'] == 'CallEnd') {
        onCallEnd();
      }
      else {
        var asd = result['sessionStatus'];
        var parsed = json.decode(result['sessionStatus']);
        SessionStatusModel sessionStatusModel = SessionStatusModel.fromJson(parsed);
        callNotRespond(sessionStatusModel);
      }

    } on PlatformException catch (e) {
      onFailure(e.toString());
    }

  }


}