import 'dart:async';

import 'package:flutter/services.dart';

class AgineekPadPlugin {
  static const MethodChannel _mainChannel = MethodChannel('agineek_pad_plugin');
  static const EventChannel _padsEventChannel =
       EventChannel('agineek_pad_plugin/pads');

  static Future<bool> startConnectPads() async {
    return await _mainChannel.invokeMethod('startConnectPads') as bool;
  }

  static Future<bool> stopConnectPads() async {
    return await _mainChannel.invokeMethod('stopConnectPads') as bool;
  }

  static Future<bool> startGame() async {
    return await _mainChannel.invokeMethod('startGame') as bool;
  }

  static Future<dynamic>? stopGame() async {
    return await _mainChannel.invokeMethod('stopGame');
  }

  static Future<bool> addPlayer(int id) async {
    return await _mainChannel.invokeMethod('addPlayer', [id]) as bool;
  }

  static Future<bool> removePlayer(int id) async {
    return await _mainChannel.invokeMethod('removePlayer', [id]) as bool;
  }

  static Stream<int> get numPadsConnected {
    return _padsEventChannel.receiveBroadcastStream()
        .distinct()
        .cast();
  }

  // TODO: create new Stream<> function for receiving pad hit/miss messages.
}
