"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());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.setBotInfo = void 0;
const RedisClient_1 = require("../helpers/RedisClient");
function setBotInfo(user) {
    var _a, _b, _c, _d, _e, _f, _g;
    return __awaiter(this, void 0, void 0, function* () {
        if (((_a = user === null || user === void 0 ? void 0 : user.name) === null || _a === void 0 ? void 0 : _a.trim()) == "botqueue") {
            let botInfo;
            if (((_b = user === null || user === void 0 ? void 0 : user.queues) === null || _b === void 0 ? void 0 : _b.length) > 0 &&
                ((_d = (_c = user.queues[0]) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.trim()) == "botqueue") {
                botInfo = JSON.stringify({
                    userId: user.id,
                    queueId: user.queues[0].id,
                    botIsOnQueue: true
                });
                botInfo = JSON.parse(botInfo);
                yield RedisClient_1.set("botInfo", botInfo);
            }
            else if (((_e = user === null || user === void 0 ? void 0 : user.queues) === null || _e === void 0 ? void 0 : _e.length) == 0 ||
                ((_g = (_f = user.queues[0]) === null || _f === void 0 ? void 0 : _f.name) === null || _g === void 0 ? void 0 : _g.trim()) != "botqueue") {
                botInfo = JSON.stringify({
                    userId: user.id,
                    queueId: 0,
                    botIsOnQueue: false
                });
                botInfo = JSON.parse(botInfo);
                yield RedisClient_1.set("botInfo", botInfo);
            }
        }
    });
}
exports.setBotInfo = setBotInfo;
