package kr.co.vividnext.sodalive.explorer

import io.reactivex.rxjava3.core.Flowable
import io.reactivex.rxjava3.core.Single
import kr.co.vividnext.sodalive.common.ApiResponse
import kr.co.vividnext.sodalive.explorer.profile.GetCheersResponse
import kr.co.vividnext.sodalive.explorer.profile.PostCreatorNoticeRequest
import kr.co.vividnext.sodalive.explorer.profile.cheers.PostWriteCheersRequest
import kr.co.vividnext.sodalive.explorer.profile.cheers.PutModifyCheersRequest
import kr.co.vividnext.sodalive.explorer.profile.donation.GetDonationAllResponse
import java.util.TimeZone

class ExplorerRepository(
    private val api: ExplorerApi
) {
    fun getExplorer(token: String) = api.getExplorer(authHeader = token)

    fun searchChannel(channel: String, token: String) = api.searchChannel(
        channel = channel,
        authHeader = token
    )

    fun getCreatorProfile(id: Long, token: String) = api.getCreatorProfile(
        id = id,
        timezone = TimeZone.getDefault().id,
        authHeader = token
    )

    fun getCreatorProfileCheers(
        creatorId: Long,
        page: Int,
        size: Int,
        token: String
    ): Flowable<ApiResponse<GetCheersResponse>> {
        return api.getCreatorProfileCheers(
            creatorId = creatorId,
            page = page - 1,
            size = size,
            timezone = TimeZone.getDefault().id,
            authHeader = token
        )
    }

    fun writeCheers(
        parentCheersId: Long?,
        creatorId: Long,
        content: String,
        token: String
    ) = api.writeCheers(
        request = PostWriteCheersRequest(
            parentId = parentCheersId,
            creatorId = creatorId,
            content = content
        ),
        authHeader = token
    )

    fun modifyCheers(
        request: PutModifyCheersRequest,
        token: String
    ) = api.modifyCheers(
        request = request,
        authHeader = token
    )

    fun writeCreatorNotice(notice: String, token: String) = api.writeCreatorNotice(
        request = PostCreatorNoticeRequest(notice),
        authHeader = token
    )

    fun getFollowerList(
        userId: Long,
        page: Int,
        size: Int,
        token: String
    ) = api.getFollowerList(
        userId = userId,
        page = page - 1,
        size = size,
        authHeader = token
    )

    fun getCreatorProfileDonationRanking(
        id: Long,
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetDonationAllResponse>> {
        return api.getCreatorProfileDonationRanking(
            id = id,
            page = page - 1,
            size = size,
            authHeader = token
        )
    }
}
