function mapDealToDealDetailResponse(deal) {
  return {
    id: deal.id,
    title: deal.title,
    description: deal.description || "",
    url: deal.url ?? null,
    price: deal.price ?? null,
    score: deal.score,

    commentsCount: deal._count?.comments ?? 0,

    status: deal.status,
    saleType: deal.saletype,
    affiliateType: deal.affiliateType,

    createdAt: deal.createdAt,
    updatedAt: deal.updatedAt,

    user: {
      id: deal.user.id,
      username: deal.user.username,
      avatarUrl: deal.user.avatarUrl ?? null,
    },

    seller: deal.seller
      ? { id: deal.seller.id, name: deal.seller.name }
      : { name: deal.customSeller || "Bilinmiyor" },

    images: deal.images.map((img) => ({
      id: img.id,
      imageUrl: img.imageUrl,
      order: img.order,
    })),

    comments: deal.comments.map((comment) => ({
      id: comment.id,
      text: comment.text,
      createdAt: comment.createdAt,
      user: {
        id: comment.user.id,
        username: comment.user.username,
        avatarUrl: comment.user.avatarUrl ?? null,
      },
    })),
  }
}

module.exports = {
  mapDealToDealDetailResponse,
}
