import 'dart:io';

import 'package:flutter/services.dart';

class ScreenStreamPlugin {
  static const _channel = MethodChannel('screen_stream');

  static Future<bool> start(String playerInfoId) async {
    try {
      await _channel.invokeMethod('start', {'playerInfoId': playerInfoId});
      return true;
    } catch (e) {
      return false;
    }
  }

  static Future<bool> stop() async {
    try {
      await _channel.invokeMethod('stop', []);
      return true;
    } catch (e) {
      return false;
    }
  }

  static Future<bool> checkPermission() async {
    if (Platform.isAndroid) {
      try {
        bool success = await _channel.invokeMethod('checkPermission', []);
        return success;
      } catch (e) {
        return false;
      }
    } else {
      return true;
    }
  }

  static Future<bool> requestPermission() async {
    if (Platform.isAndroid) {
      try {
        bool success = await _channel.invokeMethod('requestPermission', []);
        return success;
      } catch (e) {
        return false;
      }
    } else {
      return true;
    }
  }

  static Future<Map> processVideo(String path) async {
    try {
      Map result = await _channel.invokeMethod('processVideo', {'path': path});
      if (result != null) {
        return result;
      }
    } catch (e) {}
    return null;
  }

  static Future<String> getVideo(String playerInfoId) async {
    try {
      String result = await _channel.invokeMethod('getVideo', {'playerInfoId': playerInfoId});
      return result;
    } catch (e) {}
    return null;
  }
}
