import QuickAnswer from "../../models/QuickAnswer";
import AppError from "../../errors/AppError";
import Queue from "../../models/Queue";
import QueuesByUser from "../UserServices/ShowQueuesByUser";
import quickAnswearByQueueFiltered from "../../helpers/QuickAnswearByqueueFiltered";

const ShowQuickAnswerService = async (
  id: string,
  userId?: string
): Promise<QuickAnswer> => { 

  const quickAnswer = await QuickAnswer.findByPk(id, {
    include: [
      {
        model: Queue,
        as: "queues",
        attributes: ["id", "name", "color", "greetingMessage"]
      }
    ],
    order: [["queues", "id", "ASC"]]
  });

  if (!quickAnswer) {
    throw new AppError("ERR_NO_QUICK_ANSWERS_FOUND", 404);
  } 

  return quickAnswer;
};

export default ShowQuickAnswerService;
