import Whatsapp from "../../models/Whatsapp";
import AppError from "../../errors/AppError";

import WhatsappQueue from "../../models/WhatsappQueue";

const DeleteWhatsAppService = async (id: string): Promise<void> => {
  const whatsapp = await Whatsapp.findOne({
    where: { id }
  });

  if (!whatsapp) {
    throw new AppError("ERR_NO_WAPP_FOUND", 404); 
  }

  //test del
  try {
    await WhatsappQueue.destroy({ where: {whatsappId: id } }); 
  } catch (error) {
    console.log('Error on delete WhatsappQueue by whatsapp id: ',id)
  } 
  //

  await whatsapp.destroy();
};

export default DeleteWhatsAppService;
