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 Monitor from "./Monitor";
import Probe from "./Probe";
import Project from "./Project";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import OwnedThrough from "../../Types/Database/AccessControl/OwnedThrough";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import CanAccessIfCanReadOn from "../../Types/Database/CanAccessIfCanReadOn";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import TableColumn from "../../Types/Database/TableColumn";
import TableColumnType from "../../Types/Database/TableColumnType";
import TableMetadata from "../../Types/Database/TableMetadata";
import TenantColumn from "../../Types/Database/TenantColumn";
import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let MonitorProbe = class MonitorProbe extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.probe = undefined;
        this.probeId = undefined;
        this.monitor = undefined;
        this.monitorId = undefined;
        this.lastPingAt = undefined;
        this.nextPingAt = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.isEnabled = undefined;
        this.lastMonitoringLog = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], MonitorProbe.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorProbe.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "probeId",
        type: TableColumnType.Entity,
        modelType: Probe,
        title: "Probe",
        description: "Relation to Probe Resource in which this object belongs",
        example: "a1b2c3d4-e5f6-7890-ab12-cd3456ef7890",
    }),
    ManyToOne(() => {
        return Probe;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "probeId" }),
    __metadata("design:type", Probe)
], MonitorProbe.prototype, "probe", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Probe ID",
        description: "ID of your OneUptime Probe in which this object belongs",
        example: "a1b2c3d4-e5f6-7890-ab12-cd3456ef7890",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorProbe.prototype, "probeId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "monitorId",
        type: TableColumnType.Entity,
        modelType: Monitor,
        title: "Monitor",
        description: "Relation to Monitor Resource in which this object belongs",
        example: "2c3d4e5f-6a7b-8c9d-0e1f-2a3b4c5d6e7f",
    }),
    ManyToOne(() => {
        return Monitor;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "monitorId" }),
    __metadata("design:type", Monitor)
], MonitorProbe.prototype, "monitor", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Monitor ID",
        description: "ID of your OneUptime Monitor in which this object belongs",
        example: "2c3d4e5f-6a7b-8c9d-0e1f-2a3b4c5d6e7f",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorProbe.prototype, "monitorId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Date,
        example: "2024-01-15T10:30:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], MonitorProbe.prototype, "lastPingAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Date,
        example: "2024-01-15T10:35:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], MonitorProbe.prototype, "nextPingAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "createdByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Created by User",
        description: "Relation to User who created this object (if this object was created by a User)",
        example: "3d4e5f6a-7b8c-9d0e-1f2a-3b4c5d6e7f8a",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], MonitorProbe.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Created by User ID",
        description: "User ID who created this object (if this object was created by a User)",
        example: "3d4e5f6a-7b8c-9d0e-1f2a-3b4c5d6e7f8a",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorProbe.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "deletedByUserId",
        type: TableColumnType.Entity,
        title: "Deleted by User",
        modelType: User,
        description: "Relation to User who deleted this object (if this object was deleted by a User)",
        example: "4e5f6a7b-8c9d-0e1f-2a3b-4c5d6e7f8a9b",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], MonitorProbe.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Deleted by User ID",
        description: "User ID who deleted this object (if this object was deleted by a User)",
        example: "4e5f6a7b-8c9d-0e1f-2a3b-4c5d6e7f8a9b",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorProbe.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorProbe,
        ],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        defaultValue: true,
        example: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: true,
    }),
    __metadata("design:type", Boolean)
], MonitorProbe.prototype, "isEnabled", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        type: TableColumnType.JSON,
        example: {
            "step-1": {
                isSuccess: true,
                responseTimeInMs: 245,
                statusCode: 200,
            },
        },
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Object)
], MonitorProbe.prototype, "lastMonitoringLog", void 0);
MonitorProbe = __decorate([
    EnableDocumentation(),
    CanAccessIfCanReadOn("monitor"),
    TenantColumn("projectId"),
    Index(["monitorId", "probeId"]) // Composite index for efficient monitor-probe relationship queries
    ,
    Index(["monitorId", "projectId"]) // Alternative index for monitor queries within project
    ,
    Index(["probeId", "isEnabled", "nextPingAt"]) // Scheduler hot path: pick due probes per probeId
    ,
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateMonitorProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorProbe,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteMonitorProbe,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditMonitorProbe,
        ],
    }),
    CrudApiEndpoint(new Route("/monitor-probe")),
    TableMetadata({
        tableName: "MonitorProbe",
        singularName: "Monitor Probe",
        pluralName: "Monitor Probes",
        icon: IconProp.Signal,
        tableDescription: "Add probes to monitor your resource from multiple locations around the world.",
    }),
    OwnedThrough("monitorId", Monitor),
    Entity({
        name: "MonitorProbe",
    })
], MonitorProbe);
export default MonitorProbe;
//# sourceMappingURL=MonitorProbe.js.map