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 MicrosoftTeamsAuthAction from "./Auth";
import { MicrosoftTeamsScheduledMaintenanceActionType } from "./ActionTypes";
import logger from "../../../Logger";
import CaptureSpan from "../../../Telemetry/CaptureSpan";
import { TurnContext } from "botbuilder";
import ObjectID from "../../../../../Types/ObjectID";
import ScheduledMaintenanceService from "../../../../Services/ScheduledMaintenanceService";
import ScheduledMaintenance from "../../../../../Models/DatabaseModels/ScheduledMaintenance";
import ScheduledMaintenanceInternalNoteService from "../../../../Services/ScheduledMaintenanceInternalNoteService";
import ScheduledMaintenancePublicNoteService from "../../../../Services/ScheduledMaintenancePublicNoteService";
import ScheduledMaintenanceStateService from "../../../../Services/ScheduledMaintenanceStateService";
import MonitorService from "../../../../Services/MonitorService";
import Monitor from "../../../../../Models/DatabaseModels/Monitor";
import MonitorStatusService from "../../../../Services/MonitorStatusService";
import LabelService from "../../../../Services/LabelService";
import Label from "../../../../../Models/DatabaseModels/Label";
import SortOrder from "../../../../../Types/BaseDatabase/SortOrder";
import { LIMIT_PER_PROJECT } from "../../../../../Types/Database/LimitMax";
import BadDataException from "../../../../../Types/Exception/BadDataException";
import OneUptimeDate from "../../../../../Types/Date";
export default class MicrosoftTeamsScheduledMaintenanceActions {
    static isScheduledMaintenanceAction(data) {
        return (data.actionType.includes("scheduled-maintenance") ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.ViewScheduledMaintenance ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.MarkAsOngoing ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.MarkAsComplete ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.ViewAddScheduledMaintenanceNote ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.SubmitScheduledMaintenanceNote ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.ViewChangeScheduledMaintenanceState ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.SubmitChangeScheduledMaintenanceState ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.NewScheduledMaintenance ||
            data.actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.SubmitNewScheduledMaintenance);
    }
    static async handleScheduledMaintenanceAction(data) {
        const { action } = data;
        logger.debug("Handling Microsoft Teams scheduled maintenance action:", {
            projectId: data.teamsRequest.projectId.toString(),
            actionType: action.actionType,
        });
        logger.debug(action);
        try {
            switch (action.actionType) {
                case MicrosoftTeamsScheduledMaintenanceActionType.ViewScheduledMaintenance:
                    // This is handled by opening the URL directly
                    break;
                case MicrosoftTeamsScheduledMaintenanceActionType.NewScheduledMaintenance:
                    return await this.showNewScheduledMaintenanceCard(data);
                case MicrosoftTeamsScheduledMaintenanceActionType.SubmitNewScheduledMaintenance:
                    /*
                     * This is handled by handleBotScheduledMaintenanceAction through bot framework
                     * Don't process it here to avoid duplicate messages
                     */
                    break;
                default:
                    logger.debug(`Unhandled scheduled maintenance action: ${action.actionType}`, {
                        projectId: data.teamsRequest.projectId.toString(),
                        actionType: action.actionType,
                    });
                    break;
            }
        }
        catch (error) {
            logger.error("Error handling Microsoft Teams scheduled maintenance action:", {
                projectId: data.teamsRequest.projectId.toString(),
                actionType: action.actionType,
            });
            logger.error(error);
        }
        Response.sendTextResponse(data.req, data.res, "");
    }
    static async handleBotScheduledMaintenanceAction(actionType, turnContext, actionPayload, request) {
        var _a, _b, _c;
        try {
            // Handle new scheduled maintenance creation separately (doesn't need existing ID)
            if (actionType ===
                MicrosoftTeamsScheduledMaintenanceActionType.SubmitNewScheduledMaintenance) {
                // Handle new scheduled maintenance submission
                const title = actionPayload["scheduledMaintenanceTitle"] || "";
                const description = actionPayload["scheduledMaintenanceDescription"] || "";
                const startDate = actionPayload["startDate"] || "";
                const startTime = actionPayload["startTime"] || "";
                const endDate = actionPayload["endDate"] || "";
                const endTime = actionPayload["endTime"] || "";
                const monitorIds = actionPayload["scheduledMaintenanceMonitors"] || "";
                const monitorStatusId = actionPayload["monitorStatus"] || "";
                const labelIds = actionPayload["labels"] || "";
                if (!title ||
                    !description ||
                    !startDate ||
                    !startTime ||
                    !endDate ||
                    !endTime) {
                    await turnContext.sendActivity("Unable to create scheduled maintenance: missing required fields (title, description, start date/time, or end date/time).");
                    return;
                }
                if (!request.userId || !request.projectId) {
                    await turnContext.sendActivity("Unable to create scheduled maintenance: missing user or project information.");
                    return;
                }
                try {
                    // Create the scheduled maintenance
                    const scheduledMaintenanceObj = new ScheduledMaintenance();
                    scheduledMaintenanceObj.title = title;
                    scheduledMaintenanceObj.description = description;
                    scheduledMaintenanceObj.projectId = request.projectId;
                    scheduledMaintenanceObj.createdByUserId = new ObjectID(request.userId);
                    // Combine date and time for start and end
                    const startDateTime = `${startDate}T${startTime}`;
                    const endDateTime = `${endDate}T${endTime}`;
                    scheduledMaintenanceObj.startsAt =
                        OneUptimeDate.fromString(startDateTime);
                    scheduledMaintenanceObj.endsAt =
                        OneUptimeDate.fromString(endDateTime);
                    // Parse monitors
                    if (monitorIds) {
                        const monitorIdArray = monitorIds
                            .split(",")
                            .map((id) => {
                            return id.trim();
                        })
                            .filter((id) => {
                            return id;
                        });
                        if (monitorIdArray.length > 0) {
                            scheduledMaintenanceObj.monitors = monitorIdArray.map((id) => {
                                const monitor = new Monitor();
                                monitor.id = new ObjectID(id);
                                return monitor;
                            });
                        }
                    }
                    // Parse labels
                    if (labelIds) {
                        const labelIdArray = labelIds
                            .split(",")
                            .map((id) => {
                            return id.trim();
                        })
                            .filter((id) => {
                            return id;
                        });
                        if (labelIdArray.length > 0) {
                            scheduledMaintenanceObj.labels = labelIdArray.map((id) => {
                                const label = new Label();
                                label.id = new ObjectID(id);
                                return label;
                            });
                        }
                    }
                    // Save the scheduled maintenance
                    const createdScheduledMaintenance = await ScheduledMaintenanceService.create({
                        data: scheduledMaintenanceObj,
                        props: {
                            isRoot: true,
                        },
                    });
                    logger.debug("Scheduled maintenance created successfully: " +
                        ((_a = createdScheduledMaintenance.id) === null || _a === void 0 ? void 0 : _a.toString()), {
                        projectId: request.projectId.toString(),
                        scheduledMaintenanceId: (_b = createdScheduledMaintenance.id) === null || _b === void 0 ? void 0 : _b.toString(),
                    });
                    // Update monitor status if specified
                    if (monitorStatusId && monitorIds) {
                        const monitorIdArray = monitorIds
                            .split(",")
                            .map((id) => {
                            return id.trim();
                        })
                            .filter((id) => {
                            return id;
                        });
                        for (const monitorId of monitorIdArray) {
                            await MonitorService.updateOneById({
                                id: new ObjectID(monitorId),
                                data: {
                                    currentMonitorStatusId: new ObjectID(monitorStatusId),
                                },
                                props: {
                                    isRoot: true,
                                },
                            });
                        }
                    }
                    // Hide the form card by deleting it first
                    if (turnContext.activity.replyToId) {
                        await turnContext.deleteActivity(turnContext.activity.replyToId);
                    }
                    // Get the scheduled maintenance link
                    const maintenanceLink = await ScheduledMaintenanceService.getScheduledMaintenanceLinkInDashboard(createdScheduledMaintenance.projectId, createdScheduledMaintenance.id);
                    // Send confirmation message as a new message in the thread
                    await turnContext.sendActivity(`✅ Scheduled maintenance created successfully!\n\nView scheduled maintenance: ${maintenanceLink.toString()}`);
                    return;
                }
                catch (error) {
                    logger.error("Error creating scheduled maintenance from Microsoft Teams:", {
                        projectId: request.projectId.toString(),
                    });
                    logger.error(error);
                    await turnContext.sendActivity("❌ Failed to create scheduled maintenance. Please try again.");
                    return;
                }
            }
            // For all other actions, we need an existing scheduled maintenance ID
            const scheduledMaintenanceId = actionPayload["scheduledMaintenanceId"];
            if (!scheduledMaintenanceId) {
                logger.error("ScheduledMaintenance ID is required", {
                    actionType: actionType,
                });
                await turnContext.sendActivity("ScheduledMaintenance ID is required");
                return;
            }
            const scheduledMaintenance = await ScheduledMaintenanceService.findOneById({
                id: scheduledMaintenanceId,
                select: {
                    _id: true,
                    title: true,
                    description: true,
                    startsAt: true,
                    endsAt: true,
                    currentScheduledMaintenanceState: {
                        name: true,
                    },
                    projectId: true,
                },
                props: {
                    isRoot: true,
                },
            });
            if (!scheduledMaintenance) {
                logger.error("ScheduledMaintenance not found", {
                    scheduledMaintenanceId: scheduledMaintenanceId.toString(),
                });
                await turnContext.sendActivity("ScheduledMaintenance not found");
                return;
            }
            switch (actionType) {
                case MicrosoftTeamsScheduledMaintenanceActionType.ViewScheduledMaintenance:
                    await turnContext.sendActivity(`**${scheduledMaintenance.title}**\n\n${scheduledMaintenance.description}\n\nStarts: ${scheduledMaintenance.startsAt}\nEnds: ${scheduledMaintenance.endsAt}\nStatus: ${(_c = scheduledMaintenance.currentScheduledMaintenanceState) === null || _c === void 0 ? void 0 : _c.name}`);
                    break;
                case MicrosoftTeamsScheduledMaintenanceActionType.MarkAsOngoing: {
                    const ongoingState = await ScheduledMaintenanceStateService.getOngoingScheduledMaintenanceState({
                        projectId: scheduledMaintenance.projectId,
                        props: {
                            isRoot: true,
                        },
                    });
                    await ScheduledMaintenanceService.updateOneById({
                        id: scheduledMaintenanceId,
                        data: {
                            currentScheduledMaintenanceStateId: ongoingState.id,
                        },
                        props: {
                            isRoot: true,
                        },
                    });
                    await turnContext.sendActivity("ScheduledMaintenance marked as ongoing");
                    break;
                }
                case MicrosoftTeamsScheduledMaintenanceActionType.MarkAsComplete: {
                    const completedState = await ScheduledMaintenanceStateService.getCompletedScheduledMaintenanceState({
                        projectId: scheduledMaintenance.projectId,
                        props: {
                            isRoot: true,
                        },
                    });
                    await ScheduledMaintenanceService.updateOneById({
                        id: scheduledMaintenanceId,
                        data: {
                            currentScheduledMaintenanceStateId: completedState.id,
                        },
                        props: {
                            isRoot: true,
                        },
                    });
                    await turnContext.sendActivity("ScheduledMaintenance marked as complete");
                    break;
                }
                case MicrosoftTeamsScheduledMaintenanceActionType.ViewAddScheduledMaintenanceNote:
                    await turnContext.sendActivity({
                        attachments: [
                            {
                                contentType: "application/vnd.microsoft.card.adaptive",
                                content: this.buildAddScheduledMaintenanceNoteCard(scheduledMaintenanceId),
                            },
                        ],
                    });
                    break;
                case MicrosoftTeamsScheduledMaintenanceActionType.SubmitScheduledMaintenanceNote: {
                    const note = actionPayload["note"];
                    const isPublic = actionPayload["isPublic"];
                    if (!request.userId) {
                        await turnContext.sendActivity("User ID is required to add notes");
                        return;
                    }
                    if (isPublic) {
                        await ScheduledMaintenancePublicNoteService.addNote({
                            scheduledMaintenanceId: scheduledMaintenanceId,
                            note: note,
                            projectId: scheduledMaintenance.projectId,
                            userId: new ObjectID(request.userId),
                        });
                    }
                    else {
                        await ScheduledMaintenanceInternalNoteService.addNote({
                            scheduledMaintenanceId: scheduledMaintenanceId,
                            note: note,
                            projectId: scheduledMaintenance.projectId,
                            userId: new ObjectID(request.userId),
                        });
                    }
                    await turnContext.sendActivity("Note added successfully");
                    // Hide the form card by deleting it
                    if (turnContext.activity.replyToId) {
                        await turnContext.deleteActivity(turnContext.activity.replyToId);
                    }
                    break;
                }
                case MicrosoftTeamsScheduledMaintenanceActionType.ViewChangeScheduledMaintenanceState:
                    await turnContext.sendActivity({
                        attachments: [
                            {
                                contentType: "application/vnd.microsoft.card.adaptive",
                                content: await this.buildChangeScheduledMaintenanceStateCard(scheduledMaintenanceId, scheduledMaintenance.projectId),
                            },
                        ],
                    });
                    break;
                case MicrosoftTeamsScheduledMaintenanceActionType.SubmitChangeScheduledMaintenanceState: {
                    const stateId = actionPayload["stateId"];
                    await ScheduledMaintenanceService.updateOneById({
                        id: scheduledMaintenanceId,
                        data: {
                            currentScheduledMaintenanceStateId: stateId,
                        },
                        props: {
                            isRoot: true,
                        },
                    });
                    await turnContext.sendActivity("ScheduledMaintenance state changed successfully");
                    // Hide the form card by deleting it
                    if (turnContext.activity.replyToId) {
                        await turnContext.deleteActivity(turnContext.activity.replyToId);
                    }
                    break;
                }
                default:
                    logger.error(`Unknown action type: ${actionType}`, {
                        scheduledMaintenanceId: scheduledMaintenanceId.toString(),
                        actionType: actionType,
                    });
                    await turnContext.sendActivity("Unknown action type");
                    break;
            }
        }
        catch (error) {
            logger.error(`Error handling scheduled maintenance action: ${error}`, {
                actionType: actionType,
            });
            await turnContext.sendActivity("An error occurred while processing the action");
        }
    }
    static buildAddScheduledMaintenanceNoteCard(scheduledMaintenanceId) {
        return {
            type: "AdaptiveCard",
            $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
            version: "1.5",
            body: [
                {
                    type: "TextBlock",
                    text: "Add Scheduled Maintenance Note",
                    size: "Large",
                    weight: "Bolder",
                },
                {
                    type: "Input.ChoiceSet",
                    id: "noteType",
                    label: "Note Type",
                    style: "compact",
                    value: "public",
                    choices: [
                        {
                            title: "Public Note (Will be posted on Status Page)",
                            value: "public",
                        },
                        {
                            title: "Private Note (Only visible to team members)",
                            value: "private",
                        },
                    ],
                },
                {
                    type: "Input.Text",
                    id: "note",
                    label: "Note",
                    isMultiline: true,
                    placeholder: "Please type in plain text or markdown.",
                },
            ],
            actions: [
                {
                    type: "Action.Submit",
                    title: "Submit",
                    data: {
                        action: MicrosoftTeamsScheduledMaintenanceActionType.SubmitScheduledMaintenanceNote,
                        scheduledMaintenanceId: scheduledMaintenanceId.toString(),
                    },
                },
            ],
        };
    }
    static async buildChangeScheduledMaintenanceStateCard(scheduledMaintenanceId, projectId) {
        const scheduledMaintenanceStates = await ScheduledMaintenanceStateService.getAllScheduledMaintenanceStates({
            projectId: projectId,
            props: {
                isRoot: true,
            },
        });
        const choices = scheduledMaintenanceStates
            .map((state) => {
            var _a;
            return {
                title: state.name || "",
                value: ((_a = state._id) === null || _a === void 0 ? void 0 : _a.toString()) || "",
            };
        })
            .filter((choice) => {
            return choice.title && choice.value;
        });
        return {
            type: "AdaptiveCard",
            $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
            version: "1.5",
            body: [
                {
                    type: "TextBlock",
                    text: "Change Scheduled Maintenance State",
                    size: "Large",
                    weight: "Bolder",
                },
                {
                    type: "Input.ChoiceSet",
                    id: "stateId",
                    label: "Scheduled Maintenance State",
                    style: "compact",
                    choices: choices,
                },
            ],
            actions: [
                {
                    type: "Action.Submit",
                    title: "Change",
                    data: {
                        action: MicrosoftTeamsScheduledMaintenanceActionType.SubmitChangeScheduledMaintenanceState,
                        scheduledMaintenanceId: scheduledMaintenanceId.toString(),
                    },
                },
            ],
        };
    }
    static async showNewScheduledMaintenanceCard(data) {
        var _a;
        const { teamsRequest, req, res } = data;
        logger.debug("Showing new scheduled maintenance card for Microsoft Teams", {
            projectId: (_a = teamsRequest.projectId) === null || _a === void 0 ? void 0 : _a.toString(),
        });
        // Send empty response first
        Response.sendTextResponse(req, res, "");
        if (!teamsRequest.projectId) {
            logger.error("Project ID not found in Teams request");
            return;
        }
        // Build the adaptive card with form fields
        const card = await this.buildNewScheduledMaintenanceCard(teamsRequest.projectId);
        /*
         * Send card as a message (note: in real Teams bot, this would be sent via TurnContext)
         * For now, we'll just log it. The actual sending will be done through the bot framework
         */
        logger.debug("New scheduled maintenance card built:", {
            projectId: teamsRequest.projectId.toString(),
        });
        logger.debug(JSON.stringify(card, null, 2));
    }
    static async submitNewScheduledMaintenance(data) {
        var _a, _b;
        const { teamsRequest, req, res } = data;
        const { userId, projectId } = teamsRequest;
        logger.debug("Submitting new scheduled maintenance from Microsoft Teams", {
            projectId: projectId === null || projectId === void 0 ? void 0 : projectId.toString(),
        });
        if (!projectId) {
            return Response.sendErrorResponse(req, res, new BadDataException("Invalid Project ID"));
        }
        if (!userId) {
            return Response.sendErrorResponse(req, res, new BadDataException("Invalid User ID"));
        }
        // Send early response
        Response.sendTextResponse(req, res, "");
        // Extract form data from the payload
        const payload = teamsRequest.payload || {};
        const value = payload["value"] || {};
        const title = value["scheduledMaintenanceTitle"] || "";
        const description = value["scheduledMaintenanceDescription"] || "";
        const startDate = value["startDate"] || "";
        const endDate = value["endDate"] || "";
        const monitorIds = value["scheduledMaintenanceMonitors"] || "";
        const monitorStatusId = value["monitorStatus"] || "";
        const labelIds = value["labels"] || "";
        if (!title || !description || !startDate || !endDate) {
            logger.error("Missing required fields for scheduled maintenance creation", {
                projectId: projectId.toString(),
            });
            return;
        }
        try {
            // Get OneUptime user ID
            const oneUptimeUserId = await MicrosoftTeamsAuthAction.getOneUptimeUserIdFromTeamsUserId({
                teamsUserId: userId,
                projectId: projectId,
            });
            // Create the scheduled maintenance
            const scheduledMaintenance = new ScheduledMaintenance();
            scheduledMaintenance.title = title;
            scheduledMaintenance.description = description;
            scheduledMaintenance.projectId = projectId;
            scheduledMaintenance.createdByUserId = oneUptimeUserId;
            scheduledMaintenance.startsAt = OneUptimeDate.fromString(startDate);
            scheduledMaintenance.endsAt = OneUptimeDate.fromString(endDate);
            // Parse monitors
            if (monitorIds) {
                const monitorIdArray = monitorIds
                    .split(",")
                    .map((id) => {
                    return id.trim();
                })
                    .filter((id) => {
                    return id;
                });
                if (monitorIdArray.length > 0) {
                    scheduledMaintenance.monitors = monitorIdArray.map((id) => {
                        const monitor = new Monitor();
                        monitor.id = new ObjectID(id);
                        return monitor;
                    });
                }
            }
            // Parse labels
            if (labelIds) {
                const labelIdArray = labelIds
                    .split(",")
                    .map((id) => {
                    return id.trim();
                })
                    .filter((id) => {
                    return id;
                });
                if (labelIdArray.length > 0) {
                    scheduledMaintenance.labels = labelIdArray.map((id) => {
                        const label = new Label();
                        label.id = new ObjectID(id);
                        return label;
                    });
                }
            }
            // Save the scheduled maintenance
            const createdScheduledMaintenance = await ScheduledMaintenanceService.create({
                data: scheduledMaintenance,
                props: {
                    isRoot: true,
                },
            });
            logger.debug("Scheduled maintenance created successfully: " +
                ((_a = createdScheduledMaintenance.id) === null || _a === void 0 ? void 0 : _a.toString()), {
                projectId: projectId.toString(),
                scheduledMaintenanceId: (_b = createdScheduledMaintenance.id) === null || _b === void 0 ? void 0 : _b.toString(),
            });
            // Update monitor status if specified
            if (monitorStatusId && monitorIds) {
                const monitorIdArray = monitorIds
                    .split(",")
                    .map((id) => {
                    return id.trim();
                })
                    .filter((id) => {
                    return id;
                });
                for (const monitorId of monitorIdArray) {
                    await MonitorService.updateOneById({
                        id: new ObjectID(monitorId),
                        data: {
                            currentMonitorStatusId: new ObjectID(monitorStatusId),
                        },
                        props: {
                            isRoot: true,
                        },
                    });
                }
            }
            logger.debug("New scheduled maintenance created from Microsoft Teams successfully", {
                projectId: projectId.toString(),
            });
        }
        catch (error) {
            logger.error("Error creating scheduled maintenance from Microsoft Teams:", {
                projectId: projectId.toString(),
            });
            logger.error(error);
        }
    }
    static async buildNewScheduledMaintenanceCard(projectId) {
        // Fetch monitors
        const monitors = await MonitorService.findBy({
            query: {
                projectId: projectId,
            },
            select: {
                name: true,
            },
            props: {
                isRoot: true,
            },
            limit: LIMIT_PER_PROJECT,
            skip: 0,
        });
        const monitorChoices = monitors
            .map((monitor) => {
            var _a;
            return {
                title: monitor.name || "",
                value: ((_a = monitor._id) === null || _a === void 0 ? void 0 : _a.toString()) || "",
            };
        })
            .filter((choice) => {
            return choice.title && choice.value;
        });
        // Fetch monitor statuses
        const monitorStatuses = await MonitorStatusService.findBy({
            query: {
                projectId: projectId,
            },
            select: {
                name: true,
            },
            props: {
                isRoot: true,
            },
            sort: {
                priority: SortOrder.Ascending,
            },
            limit: LIMIT_PER_PROJECT,
            skip: 0,
        });
        const monitorStatusChoices = monitorStatuses
            .map((status) => {
            var _a;
            return {
                title: status.name || "",
                value: ((_a = status._id) === null || _a === void 0 ? void 0 : _a.toString()) || "",
            };
        })
            .filter((choice) => {
            return choice.title && choice.value;
        });
        // Fetch labels
        const labels = await LabelService.findBy({
            query: {
                projectId: projectId,
            },
            select: {
                name: true,
            },
            props: {
                isRoot: true,
            },
            limit: LIMIT_PER_PROJECT,
            skip: 0,
        });
        const labelChoices = labels
            .map((label) => {
            var _a;
            return {
                title: label.name || "",
                value: ((_a = label._id) === null || _a === void 0 ? void 0 : _a.toString()) || "",
            };
        })
            .filter((choice) => {
            return choice.title && choice.value;
        });
        // Build the card
        const bodyElements = [
            {
                type: "TextBlock",
                text: "Create New Scheduled Maintenance",
                size: "Large",
                weight: "Bolder",
            },
            {
                type: "Input.Text",
                id: "scheduledMaintenanceTitle",
                label: "Event Title",
                placeholder: "Enter maintenance event title",
                isRequired: true,
            },
            {
                type: "Input.Text",
                id: "scheduledMaintenanceDescription",
                label: "Event Description",
                placeholder: "Enter maintenance event description",
                isMultiline: true,
                isRequired: true,
            },
            {
                type: "Input.Date",
                id: "startDate",
                label: "Start Date",
                isRequired: true,
            },
            {
                type: "Input.Time",
                id: "startTime",
                label: "Start Time",
                isRequired: true,
            },
            {
                type: "Input.Date",
                id: "endDate",
                label: "End Date",
                isRequired: true,
            },
            {
                type: "Input.Time",
                id: "endTime",
                label: "End Time",
                isRequired: true,
            },
        ];
        // Add monitor multi-select if we have monitors
        if (monitorChoices.length > 0) {
            bodyElements.push({
                type: "Input.ChoiceSet",
                id: "scheduledMaintenanceMonitors",
                label: "Affected Monitors (Optional)",
                style: "compact",
                isMultiSelect: true,
                choices: monitorChoices,
            });
        }
        // Add monitor status dropdown if we have statuses and monitors
        if (monitorStatusChoices.length > 0 && monitorChoices.length > 0) {
            bodyElements.push({
                type: "Input.ChoiceSet",
                id: "monitorStatus",
                label: "Change Monitor Status To (Optional)",
                style: "compact",
                choices: monitorStatusChoices,
            });
        }
        // Add labels multi-select if we have labels
        if (labelChoices.length > 0) {
            bodyElements.push({
                type: "Input.ChoiceSet",
                id: "labels",
                label: "Labels (Optional)",
                style: "compact",
                isMultiSelect: true,
                choices: labelChoices,
            });
        }
        return {
            type: "AdaptiveCard",
            $schema: "http://adaptivecards.io/schemas/adaptive-card.json",
            version: "1.5",
            body: bodyElements,
            actions: [
                {
                    type: "Action.Submit",
                    title: "Create Maintenance Event",
                    data: {
                        action: MicrosoftTeamsScheduledMaintenanceActionType.SubmitNewScheduledMaintenance,
                    },
                },
            ],
        };
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Boolean)
], MicrosoftTeamsScheduledMaintenanceActions, "isScheduledMaintenanceAction", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsScheduledMaintenanceActions, "handleScheduledMaintenanceAction", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [String, TurnContext, Object, Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsScheduledMaintenanceActions, "handleBotScheduledMaintenanceAction", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsScheduledMaintenanceActions, "showNewScheduledMaintenanceCard", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], MicrosoftTeamsScheduledMaintenanceActions, "submitNewScheduledMaintenance", null);
//# sourceMappingURL=ScheduledMaintenance.js.map