var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import Response from "../../../Response";
import { MicrosoftTeamsMonitorActionType } from "./ActionTypes";
import logger from "../../../Logger";
import CaptureSpan from "../../../Telemetry/CaptureSpan";
import ObjectID from "../../../../../Types/ObjectID";
import MonitorService from "../../../../Services/MonitorService";
export default class MicrosoftTeamsMonitorActions {
    static isMonitorAction(data) {
        return (data.actionType === MicrosoftTeamsMonitorActionType.ViewMonitor ||
            data.actionType === MicrosoftTeamsMonitorActionType.EnableMonitor ||
            data.actionType === MicrosoftTeamsMonitorActionType.DisableMonitor);
    }
    static async handleMonitorAction(data) {
        const { action } = data;
        logger.debug("Handling Microsoft Teams monitor action:", {
            projectId: data.teamsRequest.projectId.toString(),
            actionType: action.actionType,
        });
        logger.debug(action);
        try {
            switch (action.actionType) {
                case MicrosoftTeamsMonitorActionType.ViewMonitor:
                    // This is handled by opening the URL directly
                    break;
                default:
                    logger.debug("Unhandled monitor action: " + action.actionType, {
                        projectId: data.teamsRequest.projectId.toString(),
                        actionType: action.actionType,
                    });
                    break;
            }
        }
        catch (error) {
            logger.error("Error handling Microsoft Teams monitor action:", {
                projectId: data.teamsRequest.projectId.toString(),
                actionType: action.actionType,
            });
            logger.error(error);
        }
        Response.sendTextResponse(data.req, data.res, "");
    }
    static async handleBotMonitorAction(data) {
        var _a;
        const { actionType, actionValue, projectId, turnContext } = data;
        if (actionType === MicrosoftTeamsMonitorActionType.ViewMonitor) {
            if (!actionValue) {
                await turnContext.sendActivity("Unable to view monitor: missing monitor id.");
                return;
            }
            const monitor = await MonitorService.findOneBy({
                query: {
                    _id: actionValue,
                    projectId: projectId,
                },
                select: {
                    _id: true,
                    name: true,
                    description: true,
                    monitorType: true,
                    currentMonitorStatus: {
                        name: true,
                    },
                    disableActiveMonitoring: true,
                    createdAt: true,
                },
                props: {
                    isRoot: true,
                },
            });
            if (!monitor) {
                await turnContext.sendActivity("Monitor not found.");
                return;
            }
            const message = `**Monitor Details**\n\n**Name:** ${monitor.name}\n**Description:** ${monitor.description || "No description"}\n**Type:** ${monitor.monitorType}\n**Status:** ${((_a = monitor.currentMonitorStatus) === null || _a === void 0 ? void 0 : _a.name) || "Unknown"}\n**Enabled:** ${monitor.disableActiveMonitoring ? "No" : "Yes"}\n**Created At:** ${monitor.createdAt ? new Date(monitor.createdAt).toLocaleString() : "Unknown"}`;
            await turnContext.sendActivity(message);
            return;
        }
        if (actionType === MicrosoftTeamsMonitorActionType.EnableMonitor) {
            if (!actionValue) {
                await turnContext.sendActivity("Unable to enable monitor: missing monitor id.");
                return;
            }
            await MonitorService.updateOneById({
                id: new ObjectID(actionValue),
                data: {
                    disableActiveMonitoring: false,
                },
                props: {
                    isRoot: true,
                },
            });
            await turnContext.sendActivity("✅ Monitor enabled successfully.");
            return;
        }
        if (actionType === MicrosoftTeamsMonitorActionType.DisableMonitor) {
            if (!actionValue) {
                await turnContext.sendActivity("Unable to disable monitor: missing monitor id.");
                return;
            }
            await MonitorService.updateOneById({
                id: new ObjectID(actionValue),
                data: {
                    disableActiveMonitoring: true,
                },
                props: {
                    isRoot: true,
                },
            });
            await turnContext.sendActivity("✅ Monitor disabled successfully.");
            return;
        }
        // Default fallback for unimplemented actions
        await turnContext.sendActivity("Sorry, but the action " +
            actionType +
            " you requested is not implemented yet.");
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Boolean)
], MicrosoftTeamsMonitorActions, "isMonitorAction", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsMonitorActions, "handleMonitorAction", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsMonitorActions, "handleBotMonitorAction", null);
//# sourceMappingURL=Monitor.js.map