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.GaidUpdateRequest
import kr.co.vividnext.sodalive.main.PushTokenUpdateRequest
import kr.co.vividnext.sodalive.mypage.MyPageResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileResponse
import kr.co.vividnext.sodalive.mypage.profile.ProfileUpdateRequest
import kr.co.vividnext.sodalive.settings.notification.UpdateNotificationSettingRequest
import kr.co.vividnext.sodalive.settings.signout.SignOutRequest
import kr.co.vividnext.sodalive.user.find_password.ForgotPasswordRequest
import kr.co.vividnext.sodalive.user.login.LoginRequest
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,
        follow: Boolean = true,
        notify: Boolean = true,
        token: String
    ) = userApi.creatorFollow(
        request = CreatorFollowRequestRequest(
            creatorId = creatorId,
            isActive = follow,
            isNotify = notify
        ),
        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)

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

    fun checkNickname(nickname: String) = userApi.checkNickname(nickname)

    fun changeNickname(
        request: ProfileUpdateRequest,
        token: String
    ) = userApi.changeNickname(request = request, authHeader = token)

    fun updateProfileImage(
        multipartFile: MultipartBody.Part,
        token: String
    ): Single<ApiResponse<String>> {
        return userApi.updateProfileImage(multipartFile, authHeader = token)
    }

    fun updateProfile(
        request: ProfileUpdateRequest,
        token: String
    ): Single<ApiResponse<ProfileResponse>> {
        return userApi.updateProfile(request, authHeader = token)
    }

    fun getProfile(token: String): Single<ApiResponse<ProfileResponse>> {
        return userApi.getMyProfile(authHeader = token)
    }

    fun updateGaid(
        request: GaidUpdateRequest,
        token: String
    ): Single<ApiResponse<Any>> {
        return userApi.updateGaid(request, authHeader = token)
    }

    fun getBlockedMemberList(page: Int, size: Int, token: String) = userApi.getBlockedMemberList(
        page = page - 1,
        size = size,
        authHeader = token
    )

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

    fun getMemberProfile(
        id: Long,
        token: String
    ) = userApi.getMemberProfile(id = id, authHeader = token)
}
