import UserMiddleware from "../Middleware/UserAuthorization";
import MonitorGroupService from "../Services/MonitorGroupService";
import Response from "../Utils/Response";
import BaseAPI from "./BaseAPI";
import CommonAPI from "./CommonAPI";
import OneUptimeDate from "../../Types/Date";
import BadDataException from "../../Types/Exception/BadDataException";
import ObjectID from "../../Types/ObjectID";
import MonitorGroup from "../../Models/DatabaseModels/MonitorGroup";
import MonitorStatus from "../../Models/DatabaseModels/MonitorStatus";
import MonitorStatusTimeline from "../../Models/DatabaseModels/MonitorStatusTimeline";
export default class MonitorGroupAPI extends BaseAPI {
    constructor() {
        var _a, _b;
        super(MonitorGroup, MonitorGroupService);
        this.router.post(`${(_a = new this.entityType()
            .getCrudApiPath()) === null || _a === void 0 ? void 0 : _a.toString()}/current-status/:monitorGroupId`, UserMiddleware.getUserMiddleware, async (req, res, next) => {
            try {
                // get group id.
                if (!req.params["monitorGroupId"]) {
                    throw new BadDataException("Monitor group id is required.");
                }
                const currentStatus = await this.service.getCurrentStatus(new ObjectID(req.params["monitorGroupId"].toString()), await CommonAPI.getDatabaseCommonInteractionProps(req));
                return Response.sendEntityResponse(req, res, currentStatus, MonitorStatus);
            }
            catch (err) {
                next(err);
            }
        });
        this.router.post(`${(_b = new this.entityType()
            .getCrudApiPath()) === null || _b === void 0 ? void 0 : _b.toString()}/timeline/:monitorGroupId`, UserMiddleware.getUserMiddleware, async (req, res, next) => {
            try {
                // get group id.
                if (!req.params["monitorGroupId"]) {
                    throw new BadDataException("Monitor group id is required.");
                }
                const startDate = OneUptimeDate.getSomeDaysAgo(90);
                const endDate = OneUptimeDate.getCurrentDate();
                const timeline = await this.service.getStatusTimeline(new ObjectID(req.params["monitorGroupId"].toString()), startDate, endDate, await CommonAPI.getDatabaseCommonInteractionProps(req));
                return Response.sendEntityArrayResponse(req, res, timeline, timeline.length, MonitorStatusTimeline);
            }
            catch (err) {
                next(err);
            }
        });
    }
}
//# sourceMappingURL=MonitorGroupAPI.js.map