import { UserEntity, UserType } from '../entities/user.entity';

/**
 * User query options for admin
 */
export interface UserQueryOptions {
  type?: UserType;
  phone?: string;
  nickname?: string;
  page?: number;
  pageSize?: number;
  sortBy?: 'createdAt' | 'lastActiveAt';
  sortOrder?: 'ASC' | 'DESC';
}

/**
 * Paginated result
 */
export interface PaginatedUsers {
  items: UserEntity[];
  total: number;
  page: number;
  pageSize: number;
  totalPages: number;
}

/**
 * User Repository Interface
 * Defines the contract for user data persistence
 */
export interface IUserRepository {
  /**
   * Save or update a user
   */
  save(user: UserEntity): Promise<UserEntity>;

  /**
   * Find user by ID
   */
  findById(id: string): Promise<UserEntity | null>;

  /**
   * Find user by phone number
   */
  findByPhone(phone: string): Promise<UserEntity | null>;

  /**
   * Find user by fingerprint
   */
  findByFingerprint(fingerprint: string): Promise<UserEntity | null>;

  /**
   * Update last active timestamp
   */
  updateLastActive(userId: string): Promise<void>;

  /**
   * Find all users with pagination and filters (admin)
   */
  findAll(options: UserQueryOptions): Promise<PaginatedUsers>;

  /**
   * Count users by type (admin)
   */
  countByType(): Promise<Record<UserType, number>>;

  /**
   * Search users by keyword (phone or nickname)
   */
  search(keyword: string, limit?: number): Promise<UserEntity[]>;
}

/**
 * Dependency injection token for IUserRepository
 */
export const USER_REPOSITORY = Symbol('IUserRepository');
