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

// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import

import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';
import 'package:freezed_annotation/freezed_annotation.dart' hide protected;

import '../frb_generated.dart';
import 'error.dart';
import 'metadata.dart';

part 'user_search.freezed.dart';

// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `assert_fields_are_eq`, `assert_fields_are_eq`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from`, `from`, `from`

Stream<UserSearchUpdate> searchUsers({
  required String accountPubkey,
  required String query,
  required int radiusStart,
  required int radiusEnd,
}) => RustLib.instance.api.crateApiUserSearchSearchUsers(
  accountPubkey: accountPubkey,
  query: query,
  radiusStart: radiusStart,
  radiusEnd: radiusEnd,
);

enum MatchQuality {
  exact,
  prefix,
  contains,
}

enum MatchedField {
  name,
  nip05,
  displayName,
  about,
}

@freezed
sealed class SearchUpdateTrigger with _$SearchUpdateTrigger {
  const SearchUpdateTrigger._();

  const factory SearchUpdateTrigger.radiusStarted({
    required int radius,
  }) = SearchUpdateTrigger_RadiusStarted;
  const factory SearchUpdateTrigger.resultsFound() = SearchUpdateTrigger_ResultsFound;
  const factory SearchUpdateTrigger.radiusCompleted({
    required int radius,
    required BigInt totalPubkeysSearched,
  }) = SearchUpdateTrigger_RadiusCompleted;
  const factory SearchUpdateTrigger.radiusTimeout({
    required int radius,
  }) = SearchUpdateTrigger_RadiusTimeout;
  const factory SearchUpdateTrigger.searchCompleted({
    required int finalRadius,
    required BigInt totalResults,
  }) = SearchUpdateTrigger_SearchCompleted;
  const factory SearchUpdateTrigger.error({
    required String message,
  }) = SearchUpdateTrigger_Error;
}

class UserSearchResult {
  final String pubkey;
  final FlutterMetadata metadata;
  final int radius;
  final MatchQuality matchQuality;
  final MatchedField bestField;
  final List<MatchedField> matchedFields;

  const UserSearchResult({
    required this.pubkey,
    required this.metadata,
    required this.radius,
    required this.matchQuality,
    required this.bestField,
    required this.matchedFields,
  });

  @override
  int get hashCode =>
      pubkey.hashCode ^
      metadata.hashCode ^
      radius.hashCode ^
      matchQuality.hashCode ^
      bestField.hashCode ^
      matchedFields.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is UserSearchResult &&
          runtimeType == other.runtimeType &&
          pubkey == other.pubkey &&
          metadata == other.metadata &&
          radius == other.radius &&
          matchQuality == other.matchQuality &&
          bestField == other.bestField &&
          matchedFields == other.matchedFields;
}

class UserSearchUpdate {
  final SearchUpdateTrigger trigger;
  final List<UserSearchResult> newResults;
  final BigInt totalResultCount;

  const UserSearchUpdate({
    required this.trigger,
    required this.newResults,
    required this.totalResultCount,
  });

  @override
  int get hashCode => trigger.hashCode ^ newResults.hashCode ^ totalResultCount.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is UserSearchUpdate &&
          runtimeType == other.runtimeType &&
          trigger == other.trigger &&
          newResults == other.newResults &&
          totalResultCount == other.totalResultCount;
}
