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

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import '../frb_generated.dart';
import 'error.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These functions are ignored because they are not marked as `pub`: `extract_creq_from_uri`, `parse_payment_request_inner`, `percent_decode`, `wait_for_nostr_payment_inner`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<CreatedPaymentRequest>>
abstract class CreatedPaymentRequest implements RustOpaqueInterface {
  String get creqA;

  String get creqB;

  NostrListenerHandle get listenerHandle;

  set creqA(String creqA);

  set creqB(String creqB);

  set listenerHandle(NostrListenerHandle listenerHandle);
}

// Rust type: RustOpaqueMoi<flutter_rust_bridge::for_generated::RustAutoOpaqueInner<NostrListenerHandle>>
abstract class NostrListenerHandle implements RustOpaqueInterface {
  /// Reconstruct a handle from persisted data (e.g. after app restart).
  static NostrListenerHandle fromPersisted({
    required PersistedRequestData data,
  }) => RustLib.instance.api
      .crateApiPaymentRequestNostrListenerHandleFromPersisted(data: data);

  /// Export handle data for persistence (e.g. SharedPreferences).
  /// The secret key is exposed as hex — the caller is responsible
  /// for storing it securely.
  PersistedRequestData toPersisted();
}

/// Parameters for creating a payment request.
class CreateRequestParams {
  /// Amount to request (in smallest unit, e.g. sats)
  final BigInt? amount;

  /// Currency unit ("sat", "usd", etc.)
  final String unit;

  /// Human-readable description
  final String? description;

  /// Nostr relay URLs for the transport
  final List<String> nostrRelays;

  const CreateRequestParams({
    this.amount,
    required this.unit,
    this.description,
    required this.nostrRelays,
  });

  @override
  int get hashCode =>
      amount.hashCode ^
      unit.hashCode ^
      description.hashCode ^
      nostrRelays.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is CreateRequestParams &&
          runtimeType == other.runtimeType &&
          amount == other.amount &&
          unit == other.unit &&
          description == other.description &&
          nostrRelays == other.nostrRelays;
}

/// Event emitted by the Nostr payment listener.
class NostrPaymentEvent {
  final NostrPaymentState state;
  final BigInt? amount;
  final String? error;

  const NostrPaymentEvent({required this.state, this.amount, this.error});

  @override
  int get hashCode => state.hashCode ^ amount.hashCode ^ error.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is NostrPaymentEvent &&
          runtimeType == other.runtimeType &&
          state == other.state &&
          amount == other.amount &&
          error == other.error;
}

/// State of a Nostr payment listener.
enum NostrPaymentState {
  /// Connected to relays, waiting for payment
  waiting,

  /// Payment received and tokens claimed
  received,

  /// Error occurred
  error,
}

/// Parsed payment request info exposed to Flutter.
/// CDK's FromStr auto-detects creqA (CBOR) vs creqB (Bech32m).
class PaymentRequestInfo {
  /// Raw encoded string (creqA... or CREQB1...)
  final String raw;

  /// Payment id
  final String? paymentId;

  /// Requested amount (in base unit)
  final BigInt? amount;

  /// Currency unit ("sat", "usd", etc.)
  final String? unit;

  /// Whether this is a single-use request
  final bool? singleUse;

  /// Accepted mints (empty = any mint)
  final List<String> mints;

  /// Human-readable description
  final String? description;

  /// Available transports
  final List<TransportInfo> transports;

  /// Whether NUT-10 spending conditions are required
  final bool hasNut10;

  const PaymentRequestInfo({
    required this.raw,
    this.paymentId,
    this.amount,
    this.unit,
    this.singleUse,
    required this.mints,
    this.description,
    required this.transports,
    required this.hasNut10,
  });

  /// Parse a payment request string (creqA, CREQB1, or bitcoin:?creq=).
  /// Supports NUT-18 (CBOR+base64) and NUT-26 (Bech32m) automatically.
  static PaymentRequestInfo parse({required String encoded}) => RustLib
      .instance
      .api
      .crateApiPaymentRequestPaymentRequestInfoParse(encoded: encoded);

  @override
  int get hashCode =>
      raw.hashCode ^
      paymentId.hashCode ^
      amount.hashCode ^
      unit.hashCode ^
      singleUse.hashCode ^
      mints.hashCode ^
      description.hashCode ^
      transports.hashCode ^
      hasNut10.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is PaymentRequestInfo &&
          runtimeType == other.runtimeType &&
          raw == other.raw &&
          paymentId == other.paymentId &&
          amount == other.amount &&
          unit == other.unit &&
          singleUse == other.singleUse &&
          mints == other.mints &&
          description == other.description &&
          transports == other.transports &&
          hasNut10 == other.hasNut10;
}

/// Serializable data for persisting a NostrListenerHandle across app restarts.
class PersistedRequestData {
  final String secretHex;
  final String pubkeyHex;
  final List<String> relays;
  final BigInt? amount;
  final String unit;
  final String mintUrl;

  const PersistedRequestData({
    required this.secretHex,
    required this.pubkeyHex,
    required this.relays,
    this.amount,
    required this.unit,
    required this.mintUrl,
  });

  @override
  int get hashCode =>
      secretHex.hashCode ^
      pubkeyHex.hashCode ^
      relays.hashCode ^
      amount.hashCode ^
      unit.hashCode ^
      mintUrl.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is PersistedRequestData &&
          runtimeType == other.runtimeType &&
          secretHex == other.secretHex &&
          pubkeyHex == other.pubkeyHex &&
          relays == other.relays &&
          amount == other.amount &&
          unit == other.unit &&
          mintUrl == other.mintUrl;
}

/// Transport info exposed to Flutter
class TransportInfo {
  /// "nostr" or "post"
  final String transportType;

  /// Target (nprofile or URL)
  final String target;

  const TransportInfo({required this.transportType, required this.target});

  @override
  int get hashCode => transportType.hashCode ^ target.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is TransportInfo &&
          runtimeType == other.runtimeType &&
          transportType == other.transportType &&
          target == other.target;
}
