// Copyright 2013 The Flutter Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v26.3.4), do not edit directly.
// See also: https://pub.dev/packages/pigeon
// ignore_for_file: unused_import, unused_shown_name
// ignore_for_file: type=lint

import 'dart:async';
import 'dart:typed_data' show Float64List, Int32List, Int64List;

import 'package:flutter/services.dart';
import 'package:meta/meta.dart' show immutable, protected, visibleForTesting;

Object? _extractReplyValueOrThrow(
  List<Object?>? replyList,
  String channelName, {
  required bool isNullValid,
}) {
  if (replyList == null) {
    throw PlatformException(
      code: 'channel-error',
      message: 'Unable to establish connection on channel: "$channelName".',
    );
  } else if (replyList.length > 1) {
    throw PlatformException(
      code: replyList[0]! as String,
      message: replyList[1] as String?,
      details: replyList[2],
    );
  } else if (!isNullValid && (replyList.isNotEmpty && replyList[0] == null)) {
    throw PlatformException(
      code: 'null-error',
      message: 'Host platform returned null value for non-null return value.',
    );
  }
  return replyList.firstOrNull;
}

bool _deepEquals(Object? a, Object? b) {
  if (identical(a, b)) {
    return true;
  }
  if (a is double && b is double) {
    if (a.isNaN && b.isNaN) {
      return true;
    }
    return a == b;
  }
  if (a is List && b is List) {
    return a.length == b.length &&
        a.indexed.every(((int, dynamic) item) => _deepEquals(item.$2, b[item.$1]));
  }
  if (a is Map && b is Map) {
    if (a.length != b.length) {
      return false;
    }
    for (final MapEntry<Object?, Object?> entryA in a.entries) {
      bool found = false;
      for (final MapEntry<Object?, Object?> entryB in b.entries) {
        if (_deepEquals(entryA.key, entryB.key)) {
          if (_deepEquals(entryA.value, entryB.value)) {
            found = true;
            break;
          } else {
            return false;
          }
        }
      }
      if (!found) {
        return false;
      }
    }
    return true;
  }
  return a == b;
}

int _deepHash(Object? value) {
  if (value is List) {
    return Object.hashAll(value.map(_deepHash));
  }
  if (value is Map) {
    int result = 0;
    for (final MapEntry<Object?, Object?> entry in value.entries) {
      result += (_deepHash(entry.key) * 31) ^ _deepHash(entry.value);
    }
    return result;
  }
  if (value is double && value.isNaN) {
    // Normalize NaN to a consistent hash.
    return 0x7FF8000000000000.hashCode;
  }
  if (value is double && value == 0.0) {
    // Normalize -0.0 to 0.0 so they have the same hash code.
    return 0.0.hashCode;
  }
  return value.hashCode;
}

/// Information passed to the platform view creation.
class PlatformVideoViewCreationParams {
  PlatformVideoViewCreationParams({required this.playerId});

  int playerId;

  List<Object?> _toList() {
    return <Object?>[playerId];
  }

  Object encode() {
    return _toList();
  }

  static PlatformVideoViewCreationParams decode(Object result) {
    result as List<Object?>;
    return PlatformVideoViewCreationParams(playerId: result[0]! as int);
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  bool operator ==(Object other) {
    if (other is! PlatformVideoViewCreationParams || other.runtimeType != runtimeType) {
      return false;
    }
    if (identical(this, other)) {
      return true;
    }
    return _deepEquals(playerId, other.playerId);
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);
}

class CreationOptions {
  CreationOptions({required this.uri, required this.httpHeaders});

  String uri;

  Map<String, String> httpHeaders;

  List<Object?> _toList() {
    return <Object?>[uri, httpHeaders];
  }

  Object encode() {
    return _toList();
  }

  static CreationOptions decode(Object result) {
    result as List<Object?>;
    return CreationOptions(
      uri: result[0]! as String,
      httpHeaders: (result[1]! as Map<Object?, Object?>).cast<String, String>(),
    );
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  bool operator ==(Object other) {
    if (other is! CreationOptions || other.runtimeType != runtimeType) {
      return false;
    }
    if (identical(this, other)) {
      return true;
    }
    return _deepEquals(uri, other.uri) && _deepEquals(httpHeaders, other.httpHeaders);
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);
}

class TexturePlayerIds {
  TexturePlayerIds({required this.playerId, required this.textureId});

  int playerId;

  int textureId;

  List<Object?> _toList() {
    return <Object?>[playerId, textureId];
  }

  Object encode() {
    return _toList();
  }

  static TexturePlayerIds decode(Object result) {
    result as List<Object?>;
    return TexturePlayerIds(playerId: result[0]! as int, textureId: result[1]! as int);
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  bool operator ==(Object other) {
    if (other is! TexturePlayerIds || other.runtimeType != runtimeType) {
      return false;
    }
    if (identical(this, other)) {
      return true;
    }
    return _deepEquals(playerId, other.playerId) && _deepEquals(textureId, other.textureId);
  }

  @override
  // ignore: avoid_equals_and_hash_code_on_mutable_classes
  int get hashCode => _deepHash(<Object?>[runtimeType, ..._toList()]);
}

class _PigeonCodec extends StandardMessageCodec {
  const _PigeonCodec();
  @override
  void writeValue(WriteBuffer buffer, Object? value) {
    if (value is int) {
      buffer.putUint8(4);
      buffer.putInt64(value);
    } else if (value is PlatformVideoViewCreationParams) {
      buffer.putUint8(129);
      writeValue(buffer, value.encode());
    } else if (value is CreationOptions) {
      buffer.putUint8(130);
      writeValue(buffer, value.encode());
    } else if (value is TexturePlayerIds) {
      buffer.putUint8(131);
      writeValue(buffer, value.encode());
    } else {
      super.writeValue(buffer, value);
    }
  }

  @override
  Object? readValueOfType(int type, ReadBuffer buffer) {
    switch (type) {
      case 129:
        return PlatformVideoViewCreationParams.decode(readValue(buffer)!);
      case 130:
        return CreationOptions.decode(readValue(buffer)!);
      case 131:
        return TexturePlayerIds.decode(readValue(buffer)!);
      default:
        return super.readValueOfType(type, buffer);
    }
  }
}

class AVFoundationVideoPlayerApi {
  /// Constructor for [AVFoundationVideoPlayerApi].  The [binaryMessenger] named argument is
  /// available for dependency injection.  If it is left null, the default
  /// BinaryMessenger will be used which routes to the host platform.
  AVFoundationVideoPlayerApi({BinaryMessenger? binaryMessenger, String messageChannelSuffix = ''})
    : pigeonVar_binaryMessenger = binaryMessenger,
      pigeonVar_messageChannelSuffix = messageChannelSuffix.isNotEmpty
          ? '.$messageChannelSuffix'
          : '';
  final BinaryMessenger? pigeonVar_binaryMessenger;

  static const MessageCodec<Object?> pigeonChannelCodec = _PigeonCodec();

  final String pigeonVar_messageChannelSuffix;

  Future<void> initialize() async {
    final pigeonVar_channelName =
        'dev.flutter.pigeon.video_player_avfoundation.AVFoundationVideoPlayerApi.initialize$pigeonVar_messageChannelSuffix';
    final pigeonVar_channel = BasicMessageChannel<Object?>(
      pigeonVar_channelName,
      pigeonChannelCodec,
      binaryMessenger: pigeonVar_binaryMessenger,
    );
    final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(null);
    final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;

    _extractReplyValueOrThrow(pigeonVar_replyList, pigeonVar_channelName, isNullValid: true);
  }

  Future<int> createForPlatformView(CreationOptions params) async {
    final pigeonVar_channelName =
        'dev.flutter.pigeon.video_player_avfoundation.AVFoundationVideoPlayerApi.createForPlatformView$pigeonVar_messageChannelSuffix';
    final pigeonVar_channel = BasicMessageChannel<Object?>(
      pigeonVar_channelName,
      pigeonChannelCodec,
      binaryMessenger: pigeonVar_binaryMessenger,
    );
    final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[params]);
    final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;

    final Object? pigeonVar_replyValue = _extractReplyValueOrThrow(
      pigeonVar_replyList,
      pigeonVar_channelName,
      isNullValid: false,
    );
    return pigeonVar_replyValue! as int;
  }

  Future<TexturePlayerIds> createForTextureView(CreationOptions creationOptions) async {
    final pigeonVar_channelName =
        'dev.flutter.pigeon.video_player_avfoundation.AVFoundationVideoPlayerApi.createForTextureView$pigeonVar_messageChannelSuffix';
    final pigeonVar_channel = BasicMessageChannel<Object?>(
      pigeonVar_channelName,
      pigeonChannelCodec,
      binaryMessenger: pigeonVar_binaryMessenger,
    );
    final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[creationOptions]);
    final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;

    final Object? pigeonVar_replyValue = _extractReplyValueOrThrow(
      pigeonVar_replyList,
      pigeonVar_channelName,
      isNullValid: false,
    );
    return pigeonVar_replyValue! as TexturePlayerIds;
  }

  Future<void> setMixWithOthers(bool mixWithOthers) async {
    final pigeonVar_channelName =
        'dev.flutter.pigeon.video_player_avfoundation.AVFoundationVideoPlayerApi.setMixWithOthers$pigeonVar_messageChannelSuffix';
    final pigeonVar_channel = BasicMessageChannel<Object?>(
      pigeonVar_channelName,
      pigeonChannelCodec,
      binaryMessenger: pigeonVar_binaryMessenger,
    );
    final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[mixWithOthers]);
    final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;

    _extractReplyValueOrThrow(pigeonVar_replyList, pigeonVar_channelName, isNullValid: true);
  }

  Future<String?> getAssetUrl(String asset, String? package) async {
    final pigeonVar_channelName =
        'dev.flutter.pigeon.video_player_avfoundation.AVFoundationVideoPlayerApi.getAssetUrl$pigeonVar_messageChannelSuffix';
    final pigeonVar_channel = BasicMessageChannel<Object?>(
      pigeonVar_channelName,
      pigeonChannelCodec,
      binaryMessenger: pigeonVar_binaryMessenger,
    );
    final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[asset, package]);
    final pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;

    final Object? pigeonVar_replyValue = _extractReplyValueOrThrow(
      pigeonVar_replyList,
      pigeonVar_channelName,
      isNullValid: true,
    );
    return pigeonVar_replyValue as String?;
  }
}
