import type { DealDetailResponse } from "../../api/deal/types"
import type { DealDetail } from "../../models/deal/DealDetail"

export function mapDealDetailResponseToDealDetail(
  api: DealDetailResponse
): DealDetail {
  return {
    id: api.id,
    title: api.title,
    description: api.description,

    url: api.url ?? undefined,
    price: api.price ?? undefined,
    score: api.score,
    commentsCount: api.commentsCount,

    status: api.status,
    saleType: api.saleType,
    affiliateType: api.affiliateType,

    createdAt: api.createdAt,
    updatedAt: api.updatedAt,

    user: api.user,
    seller:{
      name:api.seller.name,
      url:api.seller.url
    },
    images: api.images.map((img) => ({
      url: img.imageUrl,
      order: img.order,
    })),

    comments: api.comments.map((c) => ({
      id: c.id,
      text: c.text,
      createdAt: c.createdAt,
      user: c.user,
    })),
  }
}
