import { Message, MessageType, ProductMessageMetadata } from 'src/application/models';

export const getRecentProductImageUrls = (
  lastMessages: Message[],
  currentProductId: string | undefined,
) => {
  const productMessages = lastMessages
    .filter(message => message.type === MessageType.Product && message.metadata?.imageUrl)
    .map(m => m as ProductMessageMetadata);
  // put added product image at the top of the list
  return [
    ...productMessages.filter(m => m.metadata?.id === currentProductId),
    ...productMessages.filter(m => m.metadata?.id !== currentProductId),
  ].map(m => m.metadata!.imageUrl!);
};
