package com.kaixed.kchat.repository

import com.kaixed.kchat.model.response.search.User
import com.kaixed.kchat.network.RetrofitClient

/**
 * @Author: kaixed
 * @Date: 2024/11/23 14:16
 */
class UserSearchRepository {

    private val userApiService = RetrofitClient.userApiService

    // 获取用户列表
    suspend fun getUserList(username: String): Result<List<User>> {
        return try {
            val response = userApiService.getUserListByNickname(username)
            if (response.isSuccess()) {
                val userList = response.getResponseData()
                userList?.let {
                    Result.success(userList)
                } ?: Result.failure(Exception("用户列表为空"))
            } else {
                Result.failure(Exception(response.getResponseMsg()))
            }
        } catch (e: Exception) {
            Result.failure(e)
        }
    }
}
