package kr.co.vividnext.sodalive.message

import io.reactivex.rxjava3.core.Single
import kr.co.vividnext.sodalive.common.ApiResponse
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.util.TimeZone

class MessageRepository(private val api: MessageApi) {
    fun sendTextMessage(request: SendTextMessageRequest, token: String): Single<ApiResponse<Any>> {
        return api.sendTextMessage(request, authHeader = token)
    }

    fun sendVoiceMessage(
        voiceFile: MultipartBody.Part,
        request: RequestBody,
        token: String
    ): Single<ApiResponse<Any>> {
        return api.sendVoiceMessage(
            voiceFile,
            request,
            authHeader = token
        )
    }

    fun getSentTextMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetTextMessageResponse>> {
        return api.getSentTextMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun getReceivedTextMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetTextMessageResponse>> {
        return api.getReceivedTextMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun keepTextMessage(messageId: Long, token: String): Single<ApiResponse<Any>> {
        return api.keepTextMessage(
            messageId,
            authHeader = token
        )
    }

    fun getKeepTextMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetTextMessageResponse>> {
        return api.getKeepTextMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun getSentVoiceMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetVoiceMessageResponse>> {
        return api.getSentVoiceMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun getReceivedVoiceMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetVoiceMessageResponse>> {
        return api.getReceivedVoiceMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun getKeepVoiceMessage(
        page: Int,
        size: Int,
        token: String
    ): Single<ApiResponse<GetVoiceMessageResponse>> {
        return api.getKeepVoiceMessage(
            TimeZone.getDefault().id,
            page,
            size,
            authHeader = token
        )
    }

    fun deleteMessage(
        messageId: Long,
        token: String
    ): Single<ApiResponse<Any>> {
        return api.deleteMessage(messageId, authHeader = token)
    }

    fun keepVoiceMessage(messageId: Long, token: String): Single<ApiResponse<Any>> {
        return api.keepVoiceMessage(
            messageId,
            authHeader = token
        )
    }
}
