package kr.co.vividnext.sodalive.user

import io.reactivex.rxjava3.core.Single
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.explorer.profile.MemberBlockRequest
import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailUser
import kr.co.vividnext.sodalive.main.PushTokenUpdateRequest
import kr.co.vividnext.sodalive.mypage.MyPageResponse
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
import kr.co.vividnext.sodalive.user.find_password.ForgotPasswordRequest
import kr.co.vividnext.sodalive.user.login.LoginRequest
import kr.co.vividnext.sodalive.settings.signout.SignOutRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody

class UserRepository(private val userApi: UserApi) {
    fun login(request: LoginRequest) = userApi.login(request)

    fun signUp(profileImage: MultipartBody.Part?, request: RequestBody) = userApi.signUp(
        profileImage,
        request
    )

    fun findPassword(request: ForgotPasswordRequest) = userApi.findPassword(request = request)

    fun updateNotificationSettings(
        request: UpdateNotificationSettingRequest,
        token: String
    ) = userApi.updateNotificationSettings(request, authHeader = token)

    fun updatePushToken(
        request: PushTokenUpdateRequest,
        token: String
    ) = userApi.updatePushToken(request, authHeader = token)

    fun getMemberInfo(token: String) = userApi.getMemberInfo(authHeader = token)

    fun getMyPage(token: String): Single<ApiResponse<MyPageResponse>> {
        return userApi.getMyPage(authHeader = token)
    }

    fun memberBlock(
        userId: Long,
        token: String
    ) = userApi.memberBlock(request = MemberBlockRequest(userId), authHeader = token)

    fun memberUnBlock(
        userId: Long,
        token: String
    ) = userApi.memberUnBlock(request = MemberBlockRequest(userId), authHeader = token)

    fun creatorFollow(
        creatorId: Long,
        token: String
    ) = userApi.creatorFollow(
        request = CreatorFollowRequestRequest(creatorId = creatorId),
        authHeader = token
    )

    fun creatorUnFollow(
        creatorId: Long,
        token: String
    ) = userApi.creatorUnFollow(
        request = CreatorFollowRequestRequest(creatorId = creatorId),
        authHeader = token
    )

    fun searchUser(
        nickname: String,
        token: String
    ): Single<ApiResponse<List<GetRoomDetailUser>>> {
        return userApi.searchUser(nickname, authHeader = token)
    }

    fun signOut(
        request: SignOutRequest,
        token: String
    ) = userApi.signOut(request, authHeader = token)

    fun logout(token: String) = userApi.logout(authHeader = token)
    fun logoutAllDevice(token: String) = userApi.logoutAll(authHeader = token)
}
