package com.kaixed.kchat.network.service

import com.kaixed.kchat.data.objectbox.entity.UserInfo
import com.kaixed.kchat.model.request.RegisterRequest
import com.kaixed.kchat.model.request.UserRequest
import com.kaixed.kchat.model.response.friend.SearchFriends
import com.kaixed.kchat.model.response.register.Register
import com.kaixed.kchat.model.response.search.User
import com.kaixed.kchat.model.response.user.ChangeNickname
import com.kaixed.kchat.model.response.user.UploadAvatar
import com.kaixed.kchat.model.search.SearchUser
import com.kaixed.kchat.network.ApiResponse
import okhttp3.MultipartBody
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.Path

/**
 * @Author: kaixed
 * @Date: 2024/11/15 11:00
 */
interface UserApiService {

    // 注册接口
    @POST("users/register")
    suspend fun register(
        @Body registerRequest: RegisterRequest
    ): ApiResponse<Register>

    // 登录接口（根据用户名登录）
    @FormUrlEncoded
    @POST("users/login/username")
    suspend fun loginByUsername(
        @Field("username") username: String,
        @Field("password") password: String
    ): ApiResponse<UserInfo>

    // 登录接口（根据电话登录）
    @FormUrlEncoded
    @POST("users/login/telephone")
    suspend fun loginByTelephone(
        @Field("telephone") telephone: String,
        @Field("password") password: String
    ): ApiResponse<UserInfo>

    // 获取用户列表
    @GET("userList/{username}")
    suspend fun getUserListByNickname(
        @Path("username") username: String
    ): ApiResponse<List<User>>

    // 获取用户信息
    @GET("users/{username}")
    suspend fun getUserInfo(
        @Path("username") username: String
    ): ApiResponse<SearchUser>

    // 更改昵称接口
    @POST("users/info")
    suspend fun changeNickname(
        @Body userRequest: UserRequest
    ): ApiResponse<String>

    // 上传头像接口
    @Multipart
    @POST("users/avatar")
    suspend fun uploadAvatar(
        @Part("username") username: String,
        @Part file: MultipartBody.Part
    ): ApiResponse<String>
}
