// 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 'accounts.dart';
import 'error.dart';
import 'metadata.dart';
import 'relays.dart';

part 'users.freezed.dart';

// These functions are ignored because they are not marked as `pub`: `resolve_whitenoise_user`
// 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`, `clone`, `clone`, `clone`, `clone`, `clone`, `eq`, `fmt`, `fmt`, `fmt`, `fmt`, `fmt`, `from`, `from`, `from`

Stream<UserStreamItem> subscribeToUser({required String pubkey}) =>
    RustLib.instance.api.crateApiUsersSubscribeToUser(pubkey: pubkey);

Future<User> getUser({
  required String pubkey,
  required bool blockingDataSync,
}) => RustLib.instance.api.crateApiUsersGetUser(
  pubkey: pubkey,
  blockingDataSync: blockingDataSync,
);

Future<FlutterMetadata> userMetadata({
  required String pubkey,
  required bool blockingDataSync,
}) => RustLib.instance.api.crateApiUsersUserMetadata(
  pubkey: pubkey,
  blockingDataSync: blockingDataSync,
);

Future<List<Relay>> userRelays({
  required String pubkey,
  required RelayType relayType,
  required bool blockingDataSync,
}) => RustLib.instance.api.crateApiUsersUserRelays(
  pubkey: pubkey,
  relayType: relayType,
  blockingDataSync: blockingDataSync,
);

Future<KeyPackageStatus> userHasKeyPackage({
  required String pubkey,
  required bool blockingDataSync,
}) => RustLib.instance.api.crateApiUsersUserHasKeyPackage(
  pubkey: pubkey,
  blockingDataSync: blockingDataSync,
);

enum KeyPackageStatus {
  valid,
  notFound,
  incompatible,
}

class User {
  final String pubkey;
  final FlutterMetadata metadata;
  final DateTime createdAt;
  final DateTime updatedAt;

  const User({
    required this.pubkey,
    required this.metadata,
    required this.createdAt,
    required this.updatedAt,
  });

  @override
  int get hashCode => pubkey.hashCode ^ metadata.hashCode ^ createdAt.hashCode ^ updatedAt.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is User &&
          runtimeType == other.runtimeType &&
          pubkey == other.pubkey &&
          metadata == other.metadata &&
          createdAt == other.createdAt &&
          updatedAt == other.updatedAt;
}

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

  const factory UserStreamItem.initialSnapshot({
    required User user,
  }) = UserStreamItem_InitialSnapshot;
  const factory UserStreamItem.update({
    required UserUpdate update,
  }) = UserStreamItem_Update;
}

class UserUpdate {
  final UserUpdateTrigger trigger;
  final User user;

  const UserUpdate({
    required this.trigger,
    required this.user,
  });

  @override
  int get hashCode => trigger.hashCode ^ user.hashCode;

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

enum UserUpdateTrigger {
  userCreated,
  metadataChanged,
  localMetadataChanged,
}
