"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ShowQueuesByUser_1 = __importDefault(require("../services/UserServices/ShowQueuesByUser"));
const ShowWhatsAppService_1 = __importDefault(require("../services/WhatsappService/ShowWhatsAppService"));
function whatsappQueueMatchingUserQueue(userId, whatsapp, userProfile = "user") {
    return __awaiter(this, void 0, void 0, function* () {
        const userQueues = yield ShowQueuesByUser_1.default({
            profile: userProfile,
            userId: userId
        });
        if (!userQueues || (userQueues && userQueues.length == 0))
            return;
        // console.log('-----> userQueues: ', userQueues);
        let whats = yield ShowWhatsAppService_1.default(whatsapp.id);
        if (!whats.queues || (whats.queues && whats.queues.length == 0))
            return;
        const whatsappQueues = whats.queues.map((e) => e.dataValues.name);
        // console.log('-----> whatsappQueues: ', whatsappQueues);
        const matchingQueue = userQueues.find(queue => whatsappQueues.includes(queue.name));
        return matchingQueue;
    });
}
exports.default = whatsappQueueMatchingUserQueue;
