import type { ClientReviewAdminListItem } from "../@types/clientReviewRequests.js";

type ReviewRow = {
  id: number;
  clientName: string;
  reviewText: string;
  postUrl: string | null;
  starRating: number;
  isActive: boolean;
  sortOrder: number;
  createdAt: Date;
  updatedAt: Date;
};

type MediaRow = {
  id: number;
  url: string;
  altText: string | null;
  isPrimary: boolean;
  sortOrder: number;
};

export const toClientReviewListItem = (
  row: ReviewRow,
  media: MediaRow[],
): ClientReviewAdminListItem => ({
  id: row.id,
  clientName: row.clientName,
  reviewText: row.reviewText,
  postUrl: row.postUrl,
  starRating: row.starRating,
  isActive: row.isActive,
  sortOrder: row.sortOrder,
  media: media.map((m) => ({
    id: m.id,
    url: m.url,
    altText: m.altText,
    isPrimary: m.isPrimary,
    sortOrder: m.sortOrder,
  })),
  createdAt: row.createdAt,
  updatedAt: row.updatedAt,
});
