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

    score: deal.score,
    commentsCount: deal.commentCount,

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

    myVote:deal.myVote,

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

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

    seller: deal.seller
      ? { name: deal.seller.name,
          url:deal.seller.url
       }
      : { name: deal.customSeller || "" },
       
    imageUrl: deal.images?.[0]?.imageUrl || "",
  }
}

function mapPaginatedDealsToDealCardResponse(paginated) {
  return {
    ...paginated,
    results: paginated.results.map(mapDealToDealCardResponse),
  }
}

module.exports = { mapDealToDealCardResponse,mapPaginatedDealsToDealCardResponse }
