/**
 * Zulip账号关联类型定义
 *
 * 功能描述：
 * - 定义模块中使用的所有类型和接口
 * - 提供统一的类型管理和约束
 * - 确保类型安全和一致性
 * - 便于类型复用和维护
 *
 * 职责分离：
 * - 类型定义：集中管理所有模块类型
 * - 接口约束：定义数据结构和方法签名
 * - 类型安全：确保编译时类型检查
 *
 * 最近修改：
 * - 2026-01-07: 代码规范优化 - 完善类型定义和接口约束
 * - 2026-01-07: 架构优化 - 提取统一的类型定义，改善架构分层
 * - 2026-01-07: 初始创建 - 提取和统一类型定义，提高代码质量
 *
 * @author angjustinl
 * @version 1.0.1
 * @since 2026-01-07
 * @lastModified 2026-01-07
 */

/**
 * 账号状态枚举
 */
export type AccountStatus = 'active' | 'inactive' | 'suspended' | 'error';

/**
 * 创建Zulip账号关联的数据传输对象
 */
export interface CreateZulipAccountData {
  gameUserId: bigint;
  zulipUserId: number;
  zulipEmail: string;
  zulipFullName: string;
  zulipApiKeyEncrypted: string;
  status?: AccountStatus;
}

/**
 * 更新Zulip账号关联的数据传输对象
 */
export interface UpdateZulipAccountData {
  zulipFullName?: string;
  zulipApiKeyEncrypted?: string;
  status?: AccountStatus;
  lastVerifiedAt?: Date;
  lastSyncedAt?: Date;
  errorMessage?: string;
  retryCount?: number;
}

/**
 * Zulip账号查询选项
 */
export interface ZulipAccountQueryOptions {
  gameUserId?: bigint;
  zulipUserId?: number;
  zulipEmail?: string;
  status?: AccountStatus;
  includeGameUser?: boolean;
}

/**
 * 状态统计结果
 */
export interface StatusStatistics {
  active: number;
  inactive: number;
  suspended: number;
  error: number;
}

/**
 * Repository接口定义
 */
export interface IZulipAccountsRepository {
  create(data: CreateZulipAccountData): Promise<any>;
  findByGameUserId(gameUserId: bigint, includeGameUser?: boolean): Promise<any | null>;
  findByZulipUserId(zulipUserId: number, includeGameUser?: boolean): Promise<any | null>;
  findByZulipEmail(zulipEmail: string, includeGameUser?: boolean): Promise<any | null>;
  findById(id: bigint, includeGameUser?: boolean): Promise<any | null>;
  update(id: bigint, data: UpdateZulipAccountData): Promise<any | null>;
  updateByGameUserId(gameUserId: bigint, data: UpdateZulipAccountData): Promise<any | null>;
  delete(id: bigint): Promise<boolean>;
  deleteByGameUserId(gameUserId: bigint): Promise<boolean>;
  findMany(options?: ZulipAccountQueryOptions): Promise<any[]>;
  findAccountsNeedingVerification(maxAge?: number): Promise<any[]>;
  findErrorAccounts(maxRetryCount?: number): Promise<any[]>;
  batchUpdateStatus(ids: bigint[], status: AccountStatus): Promise<number>;
  getStatusStatistics(): Promise<StatusStatistics>;
  existsByEmail(email: string, excludeId?: bigint): Promise<boolean>;
  existsByZulipUserId(zulipUserId: number, excludeId?: bigint): Promise<boolean>;
  existsByGameUserId(gameUserId: bigint, excludeId?: bigint): Promise<boolean>;
}