"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 });
exports.remove = exports.createOrUpdateScheduleNotify = exports.reportScheduleNotifyByDateStartDateEnd = void 0;
const DeleteSchedulingNotifyService_1 = __importDefault(require("../services/SchedulingNotifyServices/DeleteSchedulingNotifyService"));
const ListSchedulingNotifyContactService_1 = __importDefault(require("../services/SchedulingNotifyServices/ListSchedulingNotifyContactService"));
const CreateSchedulingNotifyService_1 = __importDefault(require("../services/SchedulingNotifyServices/CreateSchedulingNotifyService"));
const ShowSchedulingNotifyService_1 = __importDefault(require("../services/SchedulingNotifyServices/ShowSchedulingNotifyService"));
const SchedulingNotifyCache_1 = require("../helpers/SchedulingNotifyCache");
const ShowStatusChatEndService_1 = __importDefault(require("../services/StatusChatEndService/ShowStatusChatEndService"));
const reportScheduleNotifyByDateStartDateEnd = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
    const { contactNumber, startDate, endDate } = req.query;
    const data_query = yield ListSchedulingNotifyContactService_1.default(contactNumber, startDate, endDate);
    return res.status(200).json(data_query);
});
exports.reportScheduleNotifyByDateStartDateEnd = reportScheduleNotifyByDateStartDateEnd;
const createOrUpdateScheduleNotify = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
    const scheduleData = req.body;
    const statusChatEnd = yield ShowStatusChatEndService_1.default({
        name: scheduleData.statusChatEndName
    });
    const schedulingNotifyCreate = yield CreateSchedulingNotifyService_1.default({
        schedulingNotifyId: scheduleData.schedulingNotifyId,
        ticketId: scheduleData.ticketId,
        statusChatEndId: statusChatEnd.id,
        schedulingDate: scheduleData.schedulingDate,
        schedulingTime: scheduleData.schedulingTime,
        message: scheduleData.message
    });
    // console.group(':::::::::::::::::: DATA schedulingNotifyCreate:\n',schedulingNotifyCreate)
    //  const io = getIO();
    //  io.emit("schedulingNotify", {action: "update", schedulingNotifyCreate });
    return res.status(200).json(schedulingNotifyCreate);
});
exports.createOrUpdateScheduleNotify = createOrUpdateScheduleNotify;
const remove = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
    const { scheduleId } = req.params;
    let schedule = yield ShowSchedulingNotifyService_1.default(scheduleId);
    yield SchedulingNotifyCache_1.deleteScheduleByTicketIdCache(schedule.ticketId);
    yield DeleteSchedulingNotifyService_1.default(scheduleId);
    return res.status(200).send();
});
exports.remove = remove;
