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 BillingService from "../../../Services/BillingService";
import MonitorService from "../../../Services/MonitorService";
import ProjectService from "../../../Services/ProjectService";
import QueryHelper from "../../Database/QueryHelper";
import ServerMeteredPlan from "./ServerMeteredPlan";
import ProductType from "../../../../Types/MeteredPlan/ProductType";
import MonitorType from "../../../../Types/Monitor/MonitorType";
import ObjectID from "../../../../Types/ObjectID";
import CaptureSpan from "../../../Utils/Telemetry/CaptureSpan";
export default class ActiveMonitoringMeteredPlan extends ServerMeteredPlan {
    getProductType() {
        return ProductType.ActiveMonitoring;
    }
    async reportQuantityToBillingProvider(projectId, options) {
        const count = await MonitorService.countBy({
            query: {
                projectId: projectId,
                monitorType: QueryHelper.notEquals(MonitorType.Manual),
            },
            props: {
                isRoot: true,
            },
        });
        // update this count in project as well.
        await ProjectService.updateOneById({
            id: projectId,
            data: {
                currentActiveMonitorsCount: count.toNumber(),
            },
            props: {
                isRoot: true,
            },
        });
        // update this count in project as well.
        const project = await ProjectService.findOneById({
            id: projectId,
            select: {
                paymentProviderMeteredSubscriptionId: true,
                paymentProviderPlanId: true,
            },
            props: {
                isRoot: true,
            },
        });
        if (project &&
            ((options === null || options === void 0 ? void 0 : options.meteredPlanSubscriptionId) ||
                project.paymentProviderMeteredSubscriptionId) &&
            project.paymentProviderPlanId) {
            await BillingService.addOrUpdateMeteredPricingOnSubscription((options === null || options === void 0 ? void 0 : options.meteredPlanSubscriptionId) ||
                project.paymentProviderMeteredSubscriptionId, this, count.toNumber());
        }
    }
}
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", String)
], ActiveMonitoringMeteredPlan.prototype, "getProductType", null);
__decorate([
    CaptureSpan(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [ObjectID, Object]),
    __metadata("design:returntype", Promise)
], ActiveMonitoringMeteredPlan.prototype, "reportQuantityToBillingProvider", null);
//# sourceMappingURL=ActiveMonitoringMeteredPlan.js.map