import QuickAnswer from "../models/QuickAnswer";

export default function quickAnswearByQueueFiltered(
  queueIds: any[],
  quickAnswers: QuickAnswer[]
) {
  let auxQuickAnswear = [];
  let repet: any[] = [];
  const userQueues = queueIds.map((uq: any) => uq.queueId);

  for (const quickAnswer of quickAnswers) {
    const { queues, id } = quickAnswer;

    if (queues.length == 0) {
      auxQuickAnswear.push(quickAnswer);
      continue;
    }

    for (const q of queues) {
      if (userQueues.includes(q.id)) {
        if (repet.includes(id)) continue;
        repet.push(id);

        auxQuickAnswear.push(quickAnswer);
      }
    }
  }
  return auxQuickAnswear;
}
