"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 CountStatusChatEndService = (startDate, endDate, queueIds) => __awaiter(void 0, void 0, void 0, function* () {
    let countStatusChatEnd;
    if (queueIds && queueIds.length > 0) {
        countStatusChatEnd = yield sequelize.query(`select t.id, s.name, count(t.id) as count from Tickets t join StatusChatEnds s on 
          t.statusChatEndId = s.id and DATE(t.createdAt) BETWEEN '${startDate} 00:00:00.000000' AND '${endDate} 23:59:59.999999'
          AND t.queueId IN (${queueIds})
          group by s.id;`, { type: QueryTypes.SELECT });
    }
    else {
        countStatusChatEnd = yield sequelize.query(`select t.id, s.name, count(t.id) as count from Tickets t join StatusChatEnds s on 
      t.statusChatEndId = s.id and DATE(t.createdAt) BETWEEN '${startDate} 00:00:00.000000' AND '${endDate} 23:59:59.999999'
      group by s.id;`, { type: QueryTypes.SELECT });
    }
    return countStatusChatEnd;
});
exports.default = CountStatusChatEndService;
