// 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 '../frb_generated.dart';
import 'error.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): `clone`, `fmt`, `from`, `from`

/// Accepts a group invite by setting user_confirmation to true.
/// The group will remain visible in the UI.
Future<AccountGroup> acceptAccountGroup({
  required String accountPubkey,
  required String mlsGroupId,
}) => RustLib.instance.api.crateApiAccountGroupsAcceptAccountGroup(
  accountPubkey: accountPubkey,
  mlsGroupId: mlsGroupId,
);

/// Declines a group invite by setting user_confirmation to false.
/// The group will be hidden from the UI but remains in MLS.
Future<AccountGroup> declineAccountGroup({
  required String accountPubkey,
  required String mlsGroupId,
}) => RustLib.instance.api.crateApiAccountGroupsDeclineAccountGroup(
  accountPubkey: accountPubkey,
  mlsGroupId: mlsGroupId,
);

Future<AccountGroup> getAccountGroup({
  required String accountPubkey,
  required String mlsGroupId,
}) => RustLib.instance.api.crateApiAccountGroupsGetAccountGroup(
  accountPubkey: accountPubkey,
  mlsGroupId: mlsGroupId,
);

Future<String?> getDmGroupWithPeer({
  required String accountPubkey,
  required String peerPubkey,
}) => RustLib.instance.api.crateApiAccountGroupsGetDmGroupWithPeer(
  accountPubkey: accountPubkey,
  peerPubkey: peerPubkey,
);

Future<void> archiveChat({
  required String accountPubkey,
  required String mlsGroupId,
}) => RustLib.instance.api.crateApiAccountGroupsArchiveChat(
  accountPubkey: accountPubkey,
  mlsGroupId: mlsGroupId,
);

Future<void> unarchiveChat({
  required String accountPubkey,
  required String mlsGroupId,
}) => RustLib.instance.api.crateApiAccountGroupsUnarchiveChat(
  accountPubkey: accountPubkey,
  mlsGroupId: mlsGroupId,
);

/// Marks a message as read for the given account.
///
/// Updates the `last_read_message_id` for the account-group pair containing
/// the specified message. This is used to compute unread counts in the chat list.
Future<AccountGroup> markMessageRead({
  required String accountPubkey,
  required String messageId,
}) => RustLib.instance.api.crateApiAccountGroupsMarkMessageRead(
  accountPubkey: accountPubkey,
  messageId: messageId,
);

/// Represents the relationship between an account and an MLS group.
///
/// This struct tracks whether a user has accepted or declined a group invite.
/// When a welcome message is received, groups are auto-joined at the MLS level,
/// but the AccountGroup tracks the user's UI-level confirmation.
///
/// Confirmation states:
/// - `Pending` = auto-joined but awaiting user decision
/// - `Accepted` = user confirmed they want to see the group
/// - `Declined` = user chose to hide the group from UI
class AccountGroup {
  final PlatformInt64? id;
  final String accountPubkey;
  final String mlsGroupId;
  final bool? userConfirmation;
  final String? welcomerPubkey;

  /// The last message the user has read in this group (hex EventId).
  /// Used to compute unread counts.
  final String? lastReadMessageId;

  /// Pin order for chat list sorting.
  /// - `None` = not pinned (appears after pinned chats)
  /// - `Some(n)` = pinned, lower values appear first
  final PlatformInt64? pinOrder;
  final PlatformInt64? archivedAt;
  final PlatformInt64 createdAt;
  final PlatformInt64 updatedAt;

  const AccountGroup({
    this.id,
    required this.accountPubkey,
    required this.mlsGroupId,
    this.userConfirmation,
    this.welcomerPubkey,
    this.lastReadMessageId,
    this.pinOrder,
    this.archivedAt,
    required this.createdAt,
    required this.updatedAt,
  });

  @override
  int get hashCode =>
      id.hashCode ^
      accountPubkey.hashCode ^
      mlsGroupId.hashCode ^
      userConfirmation.hashCode ^
      welcomerPubkey.hashCode ^
      lastReadMessageId.hashCode ^
      pinOrder.hashCode ^
      archivedAt.hashCode ^
      createdAt.hashCode ^
      updatedAt.hashCode;

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is AccountGroup &&
          runtimeType == other.runtimeType &&
          id == other.id &&
          accountPubkey == other.accountPubkey &&
          mlsGroupId == other.mlsGroupId &&
          userConfirmation == other.userConfirmation &&
          welcomerPubkey == other.welcomerPubkey &&
          lastReadMessageId == other.lastReadMessageId &&
          pinOrder == other.pinOrder &&
          archivedAt == other.archivedAt &&
          createdAt == other.createdAt &&
          updatedAt == other.updatedAt;
}
