const formatDateAsString = (value) =>
  value instanceof Date ? value.toISOString() : value ?? null

function mapCommentToDealCommentResponse(comment) {
  return {
    id: comment.id,
    text: comment.text, // eÄŸer DB'de content ise burada text'e Ã§evir
    createdAt: formatDateAsString(comment.createdAt),
    parentId:comment.parentId,
    user: {
      id: comment.user.id,
      username: comment.user.username,
      avatarUrl: comment.user.avatarUrl ?? null,
    },
  }
}

function mapCommentsToDealCommentResponse(comments) {
  return comments.map(mapCommentToDealCommentResponse)
}


function mapCommentToUserCommentResponse(c) {
  return {
    ...mapCommentToDealCommentResponse(c),
    deal: { id: c.deal.id, title: c.deal.title },
  }
}

module.exports = {
  mapCommentToDealCommentResponse,
  mapCommentsToDealCommentResponse,
  mapCommentToUserCommentResponse
}
