import { CustomerQueueManager } from './customer-queue.manager';

export class CustomerQueueDetailManager extends CustomerQueueManager {
  get data() {
    return this.tickets.map((ticket) => {
      return {
        id: ticket.id,
        code: ticket.code,
        customer: ticket.customer,
        phone: ticket.phone,
        date: ticket.date,
        summary: {
          total_activities: this.totalActivities(ticket),
          total_tickets: this.totalTickets(ticket),
          total_used: this.totalUsedTickets(ticket),
          total_queue: this.totalQueueTickets(ticket),
        },
        items: ticket.items.map((item) => {
          return {
            id: item.item_id,
            item_queue_id: item.id,
            title: item.item.item_queue?.name ?? item.item.name,
            image_url: item.item.image_url,
            summary: {
              total_tickets: item.qty,
              total_used: this.totalUsedItems(item),
              total_queue: this.totalQueueItems(item),
            },
            queue: item.queue
              .sort((a, b) => b.time - a.time)
              .map((q) => {
                return {
                  code: q.code,
                  qty: q.qty,
                  time: this.toTime(q.time),
                  status: q.status,
                };
              }),
            queue_condition: {
              available: true,
              average: 12,
              nearest: '13:10',
              crowded_level: 20,
              available_time: '15:00',
            },
          };
        }),
      };
    });
  }
}
