package com.suno.android.common_data.mappers.comments import com.suno.android.common_core_utils.Id import com.suno.android.common_core_utils.model.UserHandle import com.suno.android.common_data.comments.Comment import com.suno.android.common_data.comments.CommentRepliesResponse import com.suno.android.common_data.comments.CommentReply 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.mentions.toUserMention import com.suno.android.common_networking.remote.comments.RemoteCommentedContentEntityType 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.CommentRepliesSchema import com.suno.android.common_networking.remote.entities.CommentReplySchema 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 kotlin.time.DurationUnit import kotlin.time.toDuration fun ClipCommentsSchema.toCommentsResponse(): CommentsResponse = CommentsResponse( nextCursor = nextCursor, results = results.map(ClipCommentSchema::toComment), allowComment = allowComment, disableReason = disableReason, totalCount = totalCount, ) fun ClipCommentSchema.toComment(): Comment = Comment( id = Id(id), type = CommentType.Clip, mediaEntity = MediaEntity.ClipEntity(clipId = Id(clipId)), userId = userId, userDisplayName = userDisplayName, userHandle = UserHandle(userHandle), userAvatarUrl = userAvatarUrl, userCommentsBlocked = userCommentsBlocked, content = content, createdAt = createdAt, numLikes = numLikes, parentId = parentId?.let(::Id), numReplies = numReplies, replies = replies?.map(CommentReplySchema::toCommentReply), replyContinuationToken = replyContinuationToken, trackTimestamp = trackTimestamp?.toDuration(DurationUnit.SECONDS), reactionType = reactionType, userMentions = userMentions?.map(MentionSchema::toUserMention), ) fun CommentReplySchema.toCommentReply(): CommentReply = CommentReply( id = Id(id), userId = userId, userDisplayName = userDisplayName, userHandle = UserHandle(userHandle), userAvatarUrl = userAvatarUrl, userCommentsBlocked = userCommentsBlocked, content = content, createdAt = createdAt, numLikes = numLikes, parentId = parentId?.let(::Id), reactionType = reactionType, userMentions = userMentions?.map(MentionSchema::toUserMention), ) fun CommentRepliesSchema.toCommentRepliesResponse(): CommentRepliesResponse = CommentRepliesResponse( replies = replies.map(CommentReplySchema::toCommentReply), replyContinuationToken = replyContinuationToken, totalCount = totalCount, ) fun HookCommentsSchema.toCommentsResponse(): CommentsResponse = CommentsResponse( nextCursor = nextCursor, results = results.map(HookCommentSchema::toComment), allowComment = allowComment, disableReason = disableReason, totalCount = totalCount, ) fun HookCommentSchema.toComment(): Comment = Comment( id = Id(id), type = entityType ?.let(RemoteCommentedContentEntityType::fromString) ?.toCommentType() ?: CommentType.Clip, mediaEntity = MediaEntity.HookEntity(hookId = Id(hookId ?: "")), userId = userId, userDisplayName = userDisplayName, userHandle = UserHandle(userHandle), userAvatarUrl = userAvatarUrl, userCommentsBlocked = userCommentsBlocked, content = content, createdAt = createdAt, numLikes = numLikes, parentId = parentId?.let(::Id), numReplies = numReplies, replies = replies?.map(CommentReplySchema::toCommentReply), replyContinuationToken = replyContinuationToken, trackTimestamp = trackTimestamp?.toDuration(DurationUnit.SECONDS), reactionType = reactionType, userMentions = userMentions?.map(MentionSchema::toUserMention), ) fun RemoteCommentedContentEntityType.toCommentType() = when (this) { RemoteCommentedContentEntityType.Clip -> CommentType.Clip RemoteCommentedContentEntityType.Hook -> CommentType.Hook }