
import 'dart:convert';
import 'dart:io' show Platform;

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,int vcId,String tokenID,String generalId,int doctorId, Function() onCallEnd , Function(SessionStatusModel sessionStatusModel) onCallNotRespond ,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": vcId,
          "TokenID": tokenID,
          "generalId": generalId,
          "DoctorId": doctorId ,
        },
      );
      if(result['callResponse'] == 'CallEnd') {
        onCallEnd();
      }
      else {
        SessionStatusModel sessionStatusModel = SessionStatusModel.fromJson(Platform.isIOS ?result['sessionStatus'] :json.decode(result['sessionStatus']));
        onCallNotRespond(sessionStatusModel);
      }

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

  }


}