// This file is automatically generated, so please do not edit it.
// @generated by `flutter_rust_bridge`@ 2.11.1.

// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field

import 'api/simple.dart';
import 'dart:async';
import 'dart:convert';
import 'frb_generated.dart';
import 'frb_generated.io.dart'
    if (dart.library.js_interop) 'frb_generated.web.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

/// Main entrypoint of the Rust API
class RustLib extends BaseEntrypoint<RustLibApi, RustLibApiImpl, RustLibWire> {
  @internal
  static final instance = RustLib._();

  RustLib._();

  /// Initialize flutter_rust_bridge
  static Future<void> init({
    RustLibApi? api,
    BaseHandler? handler,
    ExternalLibrary? externalLibrary,
    bool forceSameCodegenVersion = true,
  }) async {
    await instance.initImpl(
      api: api,
      handler: handler,
      externalLibrary: externalLibrary,
      forceSameCodegenVersion: forceSameCodegenVersion,
    );
  }

  /// Initialize flutter_rust_bridge in mock mode.
  /// No libraries for FFI are loaded.
  static void initMock({required RustLibApi api}) {
    instance.initMockImpl(api: api);
  }

  /// Dispose flutter_rust_bridge
  ///
  /// The call to this function is optional, since flutter_rust_bridge (and everything else)
  /// is automatically disposed when the app stops.
  static void dispose() => instance.disposeImpl();

  @override
  ApiImplConstructor<RustLibApiImpl, RustLibWire> get apiImplConstructor =>
      RustLibApiImpl.new;

  @override
  WireConstructor<RustLibWire> get wireConstructor =>
      RustLibWire.fromExternalLibrary;

  @override
  Future<void> executeRustInitializers() async {
    await api.crateApiSimpleInitApp();
  }

  @override
  ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig =>
      kDefaultExternalLibraryLoaderConfig;

  @override
  String get codegenVersion => '2.11.1';

  @override
  int get rustContentHash => -1549536678;

  static const kDefaultExternalLibraryLoaderConfig =
      ExternalLibraryLoaderConfig(
        stem: 'rust_lib_zakat_dart',
        ioDirectory: 'rust/target/release/',
        webPrefix: 'pkg/',
      );
}

abstract class RustLibApi extends BaseApi {
  DartZakatResult crateApiSimpleCalculateBusinessZakat({
    required double cash,
    required double inventory,
    required double receivables,
    required double liabilities,
    required double goldPrice,
    required double silverPrice,
  });

  DartZakatResult crateApiSimpleCalculateSavingsZakat({
    required double cashInHand,
    required double bankBalance,
    required double goldPrice,
    required double silverPrice,
  });

  (double, double) crateApiSimpleGetNisabThresholds({
    required double goldPrice,
    required double silverPrice,
  });

  Future<void> crateApiSimpleInitApp();
}

class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
  RustLibApiImpl({
    required super.handler,
    required super.wire,
    required super.generalizedFrbRustBinding,
    required super.portManager,
  });

  @override
  DartZakatResult crateApiSimpleCalculateBusinessZakat({
    required double cash,
    required double inventory,
    required double receivables,
    required double liabilities,
    required double goldPrice,
    required double silverPrice,
  }) {
    return handler.executeSync(
      SyncTask(
        callFfi: () {
          final serializer = SseSerializer(generalizedFrbRustBinding);
          sse_encode_f_64(cash, serializer);
          sse_encode_f_64(inventory, serializer);
          sse_encode_f_64(receivables, serializer);
          sse_encode_f_64(liabilities, serializer);
          sse_encode_f_64(goldPrice, serializer);
          sse_encode_f_64(silverPrice, serializer);
          return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 1)!;
        },
        codec: SseCodec(
          decodeSuccessData: sse_decode_dart_zakat_result,
          decodeErrorData: sse_decode_String,
        ),
        constMeta: kCrateApiSimpleCalculateBusinessZakatConstMeta,
        argValues: [
          cash,
          inventory,
          receivables,
          liabilities,
          goldPrice,
          silverPrice,
        ],
        apiImpl: this,
      ),
    );
  }

  TaskConstMeta get kCrateApiSimpleCalculateBusinessZakatConstMeta =>
      const TaskConstMeta(
        debugName: "calculate_business_zakat",
        argNames: [
          "cash",
          "inventory",
          "receivables",
          "liabilities",
          "goldPrice",
          "silverPrice",
        ],
      );

  @override
  DartZakatResult crateApiSimpleCalculateSavingsZakat({
    required double cashInHand,
    required double bankBalance,
    required double goldPrice,
    required double silverPrice,
  }) {
    return handler.executeSync(
      SyncTask(
        callFfi: () {
          final serializer = SseSerializer(generalizedFrbRustBinding);
          sse_encode_f_64(cashInHand, serializer);
          sse_encode_f_64(bankBalance, serializer);
          sse_encode_f_64(goldPrice, serializer);
          sse_encode_f_64(silverPrice, serializer);
          return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 2)!;
        },
        codec: SseCodec(
          decodeSuccessData: sse_decode_dart_zakat_result,
          decodeErrorData: sse_decode_String,
        ),
        constMeta: kCrateApiSimpleCalculateSavingsZakatConstMeta,
        argValues: [cashInHand, bankBalance, goldPrice, silverPrice],
        apiImpl: this,
      ),
    );
  }

  TaskConstMeta get kCrateApiSimpleCalculateSavingsZakatConstMeta =>
      const TaskConstMeta(
        debugName: "calculate_savings_zakat",
        argNames: ["cashInHand", "bankBalance", "goldPrice", "silverPrice"],
      );

  @override
  (double, double) crateApiSimpleGetNisabThresholds({
    required double goldPrice,
    required double silverPrice,
  }) {
    return handler.executeSync(
      SyncTask(
        callFfi: () {
          final serializer = SseSerializer(generalizedFrbRustBinding);
          sse_encode_f_64(goldPrice, serializer);
          sse_encode_f_64(silverPrice, serializer);
          return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 3)!;
        },
        codec: SseCodec(
          decodeSuccessData: sse_decode_record_f_64_f_64,
          decodeErrorData: null,
        ),
        constMeta: kCrateApiSimpleGetNisabThresholdsConstMeta,
        argValues: [goldPrice, silverPrice],
        apiImpl: this,
      ),
    );
  }

  TaskConstMeta get kCrateApiSimpleGetNisabThresholdsConstMeta =>
      const TaskConstMeta(
        debugName: "get_nisab_thresholds",
        argNames: ["goldPrice", "silverPrice"],
      );

  @override
  Future<void> crateApiSimpleInitApp() {
    return handler.executeNormal(
      NormalTask(
        callFfi: (port_) {
          final serializer = SseSerializer(generalizedFrbRustBinding);
          pdeCallFfi(
            generalizedFrbRustBinding,
            serializer,
            funcId: 4,
            port: port_,
          );
        },
        codec: SseCodec(
          decodeSuccessData: sse_decode_unit,
          decodeErrorData: null,
        ),
        constMeta: kCrateApiSimpleInitAppConstMeta,
        argValues: [],
        apiImpl: this,
      ),
    );
  }

  TaskConstMeta get kCrateApiSimpleInitAppConstMeta =>
      const TaskConstMeta(debugName: "init_app", argNames: []);

  @protected
  String dco_decode_String(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return raw as String;
  }

  @protected
  bool dco_decode_bool(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return raw as bool;
  }

  @protected
  DartZakatResult dco_decode_dart_zakat_result(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    final arr = raw as List<dynamic>;
    if (arr.length != 5)
      throw Exception('unexpected arr length: expect 5 but see ${arr.length}');
    return DartZakatResult(
      zakatDue: dco_decode_f_64(arr[0]),
      isPayable: dco_decode_bool(arr[1]),
      nisabThreshold: dco_decode_f_64(arr[2]),
      wealthAmount: dco_decode_f_64(arr[3]),
      limitName: dco_decode_String(arr[4]),
    );
  }

  @protected
  double dco_decode_f_64(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return raw as double;
  }

  @protected
  Uint8List dco_decode_list_prim_u_8_strict(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return raw as Uint8List;
  }

  @protected
  (double, double) dco_decode_record_f_64_f_64(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    final arr = raw as List<dynamic>;
    if (arr.length != 2) {
      throw Exception('Expected 2 elements, got ${arr.length}');
    }
    return (dco_decode_f_64(arr[0]), dco_decode_f_64(arr[1]));
  }

  @protected
  int dco_decode_u_8(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return raw as int;
  }

  @protected
  void dco_decode_unit(dynamic raw) {
    // Codec=Dco (DartCObject based), see doc to use other codecs
    return;
  }

  @protected
  String sse_decode_String(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    var inner = sse_decode_list_prim_u_8_strict(deserializer);
    return utf8.decoder.convert(inner);
  }

  @protected
  bool sse_decode_bool(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    return deserializer.buffer.getUint8() != 0;
  }

  @protected
  DartZakatResult sse_decode_dart_zakat_result(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    var var_zakatDue = sse_decode_f_64(deserializer);
    var var_isPayable = sse_decode_bool(deserializer);
    var var_nisabThreshold = sse_decode_f_64(deserializer);
    var var_wealthAmount = sse_decode_f_64(deserializer);
    var var_limitName = sse_decode_String(deserializer);
    return DartZakatResult(
      zakatDue: var_zakatDue,
      isPayable: var_isPayable,
      nisabThreshold: var_nisabThreshold,
      wealthAmount: var_wealthAmount,
      limitName: var_limitName,
    );
  }

  @protected
  double sse_decode_f_64(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    return deserializer.buffer.getFloat64();
  }

  @protected
  Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    var len_ = sse_decode_i_32(deserializer);
    return deserializer.buffer.getUint8List(len_);
  }

  @protected
  (double, double) sse_decode_record_f_64_f_64(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    var var_field0 = sse_decode_f_64(deserializer);
    var var_field1 = sse_decode_f_64(deserializer);
    return (var_field0, var_field1);
  }

  @protected
  int sse_decode_u_8(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    return deserializer.buffer.getUint8();
  }

  @protected
  void sse_decode_unit(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
  }

  @protected
  int sse_decode_i_32(SseDeserializer deserializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    return deserializer.buffer.getInt32();
  }

  @protected
  void sse_encode_String(String self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    sse_encode_list_prim_u_8_strict(utf8.encoder.convert(self), serializer);
  }

  @protected
  void sse_encode_bool(bool self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    serializer.buffer.putUint8(self ? 1 : 0);
  }

  @protected
  void sse_encode_dart_zakat_result(
    DartZakatResult self,
    SseSerializer serializer,
  ) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    sse_encode_f_64(self.zakatDue, serializer);
    sse_encode_bool(self.isPayable, serializer);
    sse_encode_f_64(self.nisabThreshold, serializer);
    sse_encode_f_64(self.wealthAmount, serializer);
    sse_encode_String(self.limitName, serializer);
  }

  @protected
  void sse_encode_f_64(double self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    serializer.buffer.putFloat64(self);
  }

  @protected
  void sse_encode_list_prim_u_8_strict(
    Uint8List self,
    SseSerializer serializer,
  ) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    sse_encode_i_32(self.length, serializer);
    serializer.buffer.putUint8List(self);
  }

  @protected
  void sse_encode_record_f_64_f_64(
    (double, double) self,
    SseSerializer serializer,
  ) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    sse_encode_f_64(self.$1, serializer);
    sse_encode_f_64(self.$2, serializer);
  }

  @protected
  void sse_encode_u_8(int self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    serializer.buffer.putUint8(self);
  }

  @protected
  void sse_encode_unit(void self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
  }

  @protected
  void sse_encode_i_32(int self, SseSerializer serializer) {
    // Codec=Sse (Serialization based), see doc to use other codecs
    serializer.buffer.putInt32(self);
  }
}
