package kr.co.vividnext.sodalive.explorer.profile.creator_community

import kr.co.vividnext.sodalive.audio_content.comment.ModifyCommentRequest
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.PostCommunityPostLikeRequest
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.PurchasePostRequest
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.comment.CreateCommunityPostCommentRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody
import java.util.TimeZone

class CreatorCommunityRepository(private val api: CreatorCommunityApi) {
    fun getCommunityPostList(
        creatorId: Long,
        page: Int,
        size: Int,
        token: String
    ) = api.getCommunityPostList(
        creatorId = creatorId,
        page = page - 1,
        size = size,
        timezone = TimeZone.getDefault().id,
        authHeader = token
    )

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

    fun communityPostLike(postId: Long, token: String) = api.communityPostLike(
        request = PostCommunityPostLikeRequest(postId = postId),
        authHeader = token
    )

    fun getCommunityPostCommentList(
        postId: Long,
        page: Int,
        size: Int,
        token: String
    ) = api.getCommunityPostCommentList(
        postId = postId,
        page = page,
        size = size,
        timezone = TimeZone.getDefault().id,
        authHeader = token
    )

    fun registerComment(
        postId: Long,
        comment: String,
        parentId: Long? = null,
        token: String
    ) = api.createCommunityPostComment(
        request = CreateCommunityPostCommentRequest(
            comment = comment,
            postId = postId,
            parentId = parentId
        ),
        authHeader = token
    )

    fun modifyComment(request: ModifyCommentRequest, token: String) = api.modifyComment(
        request = request,
        authHeader = token
    )

    fun getCommentReplyList(commentId: Long, page: Int, size: Int, token: String) = api.getCommentReplyList(
        commentId = commentId,
        page = page,
        size = size,
        timezone = TimeZone.getDefault().id,
        authHeader = token
    )

    fun createCommunityPost(
        audioFile: MultipartBody.Part?,
        postImage: MultipartBody.Part?,
        request: RequestBody,
        token: String
    ) = api.createCommunityPost(
        audioFile = audioFile,
        postImage = postImage,
        request = request,
        authHeader = token
    )

    fun modifyCommunityPost(
        postImage: MultipartBody.Part?,
        request: RequestBody,
        token: String
    ) = api.modifyCommunityPost(
        postImage = postImage,
        request = request,
        authHeader = token
    )

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

    fun purchaseCommunityPost(postId: Long, token: String) = api.purchaseCommunityPost(
        request = PurchasePostRequest(postId = postId, timezone = TimeZone.getDefault().id),
        authHeader = token
    )
}
