import { QueueItemModel } from 'src/modules/queue/data/models/queue.model';
import { CustomerQueueManager } from './customer-queue.manager';

export class CustomerQueueItemListManager extends CustomerQueueManager {
  get data() {
    const tickets = this.tickets;
    const ticketItems = {};

    tickets.forEach((ticket) => {
      ticket.items.forEach((item) => {
        const item_id = item.item.item_queue?.id ?? item.item.id;
        const currentItem = ticketItems[item_id];
        ticketItems[item_id] = currentItem ? [...currentItem, item] : [item];
      });
    });

    return Object.values<QueueItemModel[]>(ticketItems).map((items) => {
      const item = items[0];
      const item_qty = items.reduce((acc, item) => acc + item.qty, 0);
      return {
        id: item.item_id,
        queue_item_id: item.id,
        title: item.item.item_queue?.name ?? item.item.name,
        image_url: item.item.image_url,
        qty: item_qty,

        available: true,
        average: 12,
        nearest: '13:10',
        crowded_level: 20,
        available_time: '15:00',

        queue_condition: {
          available: true,
          average: 12,
          nearest: '13:10',
          crowded_level: 20,
          available_time: '15:00',
        },
      };
    });
  }
}
