package com.suno.android.common_data.repos.comments import com.suno.android.common_core_utils.Id import com.suno.android.common_data.comments.Comment import com.suno.android.common_data.comments.CommentRepliesResponse import com.suno.android.common_data.comments.CommentType import com.suno.android.common_data.comments.CommentsResponse import com.suno.android.common_data.comments.MediaEntity import com.suno.android.common_data.mappers.comments.toComment import com.suno.android.common_data.mappers.comments.toCommentRepliesResponse import com.suno.android.common_data.mappers.comments.toCommentsResponse import com.suno.android.common_data.mentions.UserMention import com.suno.android.common_networking.extensions.ApiResult import com.suno.android.common_networking.remote.comments.ClipCommentsService import com.suno.android.common_networking.remote.entities.ClipCommentSchema import com.suno.android.common_networking.remote.entities.ClipCommentsSchema import com.suno.android.common_networking.remote.entities.CommentDeletionSchema import com.suno.android.common_networking.remote.entities.CommentReactionSchema import com.suno.android.common_networking.remote.entities.CommentRepliesSchema import com.suno.android.common_networking.remote.entities.HookCommentSchema import com.suno.android.common_networking.remote.entities.HookCommentsSchema import com.suno.android.common_networking.remote.entities.MentionSchema import com.suno.android.common_networking.remote.entities.RemoteCommentPostBody import com.suno.android.common_networking.remote.entities.RemoteCommentReactionBody import com.suno.android.common_networking.remote.entities.RemoteReportCommentBody import com.suno.android.common_networking.remote.hooks.HookCommentsService import javax.inject.Inject class DefaultCommentsRepository @Inject constructor( private val clipCommentsService: ClipCommentsService, private val hookCommentsService: HookCommentsService, ) : CommentsRepository { override suspend fun getComments( mediaEntity: MediaEntity, cursor: String?, order: String?, ): ApiResult = when (mediaEntity) { is MediaEntity.ClipEntity -> clipCommentsService.getCommentsByClipId( id = mediaEntity.clipId.value, cursor = cursor, order = order, ) .map(ClipCommentsSchema::toCommentsResponse) is MediaEntity.HookEntity -> hookCommentsService.getCommentsByHookId( id = mediaEntity.hookId.value, cursor = cursor, order = order, ) .map(HookCommentsSchema::toCommentsResponse) } override suspend fun getCommentReplies( commentId: Id, commentType: CommentType, cursor: String?, ): ApiResult = when (commentType) { CommentType.Clip -> clipCommentsService.getCommentRepliesByCommentId(commentId.value, cursor) .map(CommentRepliesSchema::toCommentRepliesResponse) CommentType.Hook -> hookCommentsService.getCommentRepliesByCommentId(commentId.value, cursor) .map(CommentRepliesSchema::toCommentRepliesResponse) } override suspend fun postComment( mediaEntity: MediaEntity, content: String, parentId: Id?, mentions: List?, trackTimestamp: Double?, ): ApiResult { val userMentions = mentions?.map { mention -> MentionSchema( start = mention.start, end = mention.end, handle = mention.handle, displayName = mention.displayName, ) } val body = RemoteCommentPostBody( content = content, parentId = parentId?.value, userMentions = userMentions, trackTimestamp = trackTimestamp, ) return when (mediaEntity) { is MediaEntity.ClipEntity -> clipCommentsService.postComment(mediaEntity.clipId.value, body) .map(ClipCommentSchema::toComment) is MediaEntity.HookEntity -> hookCommentsService.postComment(mediaEntity.hookId.value, body) .map(HookCommentSchema::toComment) } } override suspend fun reactToComment( commentId: Id, commentType: CommentType, reaction: String, ): ApiResult { val body = RemoteCommentReactionBody(reaction = reaction) return when (commentType) { CommentType.Clip -> clipCommentsService.reactToComment(commentId.value, body) CommentType.Hook -> hookCommentsService.reactToComment(commentId.value, body) } } override suspend fun reportComment( commentId: Id, commentType: CommentType, reason: String, ): ApiResult { val body = RemoteReportCommentBody(reason = reason) return when (commentType) { CommentType.Clip -> clipCommentsService.reportComment(commentId.value, body) CommentType.Hook -> hookCommentsService.reportComment(commentId.value, body) } } override suspend fun deleteComment( commentId: Id, commentType: CommentType, ): ApiResult = when (commentType) { CommentType.Clip -> clipCommentsService.deleteComment(commentId.value) CommentType.Hook -> hookCommentsService.deleteComment(commentId.value) } }