"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 });
const sequelize_1 = require("sequelize");
const dbConfig = require("../../config/database");
const sequelize = new sequelize_1.Sequelize(dbConfig);
const { QueryTypes } = require("sequelize");
const QueuesByUser = ({ profile, userId }) => __awaiter(void 0, void 0, void 0, function* () {
    let queueByUsersInfo = [];
    if (userId && profile) {
        // CONSULTANDO FILAS PELO ID DO USUARIO
        queueByUsersInfo = yield sequelize.query(`select UserQueues.userId, UserQueues.queueId, Users.name, 
            Queues.name, Queues.color from UserQueues inner join Users inner join Queues on
            UserQueues.queueId = Queues.id and  UserQueues.userId = Users.id and Users.id = '${userId}' and Users.profile = '${profile}' order by userId, queueId;`, { type: QueryTypes.SELECT });
    }
    else if (profile) {
        // CONSULTANDO FILAS PELO USUARIO
        queueByUsersInfo = yield sequelize.query(`select UserQueues.userId, UserQueues.queueId, Users.name, 
            Queues.name, Queues.color from UserQueues inner join Users inner join Queues on
            UserQueues.queueId = Queues.id and  UserQueues.userId = Users.id and Users.profile = '${profile}' order by userId, queueId;`, { type: QueryTypes.SELECT });
    }
    else if (userId) {
        queueByUsersInfo = yield sequelize.query(`select UserQueues.userId, UserQueues.queueId, Users.name, 
            Queues.name, Queues.color from UserQueues inner join Users inner join Queues on
            UserQueues.queueId = Queues.id and  UserQueues.userId = Users.id and Users.id = '${userId}' order by userId, queueId;`, { type: QueryTypes.SELECT });
    }
    // if (userId) {
    //   // CONSULTANDO FILAS PELO ID DO USUARIO
    //   queueByUsersInfo = await sequelize.query(
    //     `select UserQueues.userId, UserQueues.queueId, Users.name,
    //         Queues.name, Queues.color from UserQueues inner join Users inner join Queues on
    //         UserQueues.queueId = Queues.id and  UserQueues.userId = Users.id and Users.id = '${userId}' and Users.profile = '${profile}' order by userId, queueId;`,
    //     { type: QueryTypes.SELECT }
    //   );
    // } else {
    //   // CONSULTANDO FILAS PELO USUARIO
    //   queueByUsersInfo = await sequelize.query(
    //     `select UserQueues.userId, UserQueues.queueId, Users.name,
    //         Queues.name, Queues.color from UserQueues inner join Users inner join Queues on
    //         UserQueues.queueId = Queues.id and  UserQueues.userId = Users.id  and Users.profile = '${profile}' order by userId, queueId;`,
    //     { type: QueryTypes.SELECT }
    //   );
    // }
    return queueByUsersInfo;
});
exports.default = QueuesByUser;
