import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';

import 'atmob_channel_reader_platform_interface.dart';

/// An implementation of [AtmobChannelReaderPlatform] that uses method channels.
class MethodChannelAtmobChannelReader extends AtmobChannelReaderPlatform {
  /// The method channel used to interact with the native platform.
  @visibleForTesting
  final methodChannel = const MethodChannel('atmob_channel_reader');

  @override
  Future<void> default4Test(String channel, int tgPlatformId, int appId) async {
    if (Platform.isAndroid) {
      await methodChannel.invokeMethod<void>('default4Test', {
        'channel': channel,
        'tgPlatformId': tgPlatformId,
        'appId': appId,
      });
    }
  }

  @override
  Future<String?> getChannel() async {
    if (Platform.isAndroid) {
      return await methodChannel.invokeMethod<String>('getChannel');
    }
    if (Platform.isIOS) {
      return 'AppStore';
    }
    return null;
  }

  @override
  Future<int?> getTgPlatformId() async {
    if (Platform.isAndroid) {
      return methodChannel.invokeMethod<int>('getTgPlatformId');
    }
    return 0;
  }

  @override
  Future<int?> getAppId() async {
    if (Platform.isAndroid) {
      return methodChannel.invokeMethod<int>('getAppId');
    }
    return 0;
  }
}
