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 Label from "./Label";
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 TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import AccessControlColumn from "../../Types/Database/AccessControlColumn";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import EnableWorkflow from "../../Types/Database/EnableWorkflow";
import SlugifyColumn from "../../Types/Database/SlugifyColumn";
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 MonitorSteps from "../../Types/Monitor/MonitorSteps";
import MonitorType from "../../Types/Monitor/MonitorType";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, } from "typeorm";
let MonitorTemplate = class MonitorTemplate extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.templateName = undefined;
        this.templateDescription = undefined;
        this.slug = undefined;
        this.monitorName = undefined;
        this.monitorDescription = undefined;
        this.monitorType = undefined;
        this.monitorSteps = undefined;
        this.monitoringInterval = undefined;
        this.labels = undefined;
        this.customFields = undefined;
        this.minimumProbeAgreement = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], MonitorTemplate.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorTemplate.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Template Name",
        description: "Name of the Monitor Template",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "templateName", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.LongText,
        canReadOnRelationQuery: true,
        title: "Template Description",
        description: "Description of the Monitor Template",
    }),
    Column({
        nullable: false,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "templateDescription", void 0);
__decorate([
    Index(),
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        unique: true,
        type: TableColumnType.Slug,
        computed: true,
        title: "Slug",
        description: "Friendly globally unique name for your object",
    }),
    Column({
        nullable: false,
        type: ColumnType.Slug,
        length: ColumnLength.Slug,
        unique: true,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "slug", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "Monitor Name",
        description: "Default name applied to monitors created from this template. Users can override on creation.",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "monitorName", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Monitor Description",
        description: "Default description applied to monitors created from this template.",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "monitorDescription", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.MonitorType,
        title: "Monitor Type",
        description: "What is the type of monitor created from this template?",
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "monitorType", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        type: TableColumnType.MonitorSteps,
        required: false,
        title: "Monitor Steps",
        description: "Monitor steps and criteria copied to monitors created from this template.",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
        transformer: MonitorSteps.getDatabaseTransformer(),
    }),
    __metadata("design:type", MonitorSteps)
], MonitorTemplate.prototype, "monitorSteps", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        title: "Monitoring Interval",
        description: "Default monitoring interval for monitors created from this template",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], MonitorTemplate.prototype, "monitoringInterval", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Label,
        title: "Labels",
        description: "Default labels applied to monitors created from this template.",
    }),
    ManyToMany(() => {
        return Label;
    }, { eager: false }),
    JoinTable({
        name: "MonitorTemplateLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "monitorTemplateId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], MonitorTemplate.prototype, "labels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        type: TableColumnType.JSON,
        title: "Custom Fields",
        description: "Custom Fields on this resource.",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Object)
], MonitorTemplate.prototype, "customFields", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    TableColumn({
        type: TableColumnType.Number,
        required: false,
        title: "Minimum Probe Agreement",
        description: "Default minimum number of probes that must agree on a status before the monitor status changes.",
    }),
    Column({
        type: ColumnType.Number,
        nullable: true,
    }),
    __metadata("design:type", Number)
], MonitorTemplate.prototype, "minimumProbeAgreement", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        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)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], MonitorTemplate.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        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)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorTemplate.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        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)",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], MonitorTemplate.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        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)",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], MonitorTemplate.prototype, "deletedByUserId", void 0);
MonitorTemplate = __decorate([
    EnableDocumentation(),
    AccessControlColumn("labels"),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.CreateMonitorTemplate,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.MonitorViewer,
            Permission.ReadMonitorTemplate,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.DeleteMonitorTemplate,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.MonitorAdmin,
            Permission.MonitorMember,
            Permission.EditMonitorTemplate,
        ],
    }),
    CrudApiEndpoint(new Route("/monitor-template")),
    SlugifyColumn("templateName", "slug"),
    Entity({
        name: "MonitorTemplate",
    }),
    EnableWorkflow({
        create: true,
        delete: true,
        update: true,
        read: true,
    }),
    TableMetadata({
        tableName: "MonitorTemplate",
        singularName: "Monitor Template",
        pluralName: "Monitor Templates",
        icon: IconProp.AltGlobe,
        tableDescription: "Reusable monitor template. Use it to create new monitors with the same configuration.",
    })
], MonitorTemplate);
export default MonitorTemplate;
//# sourceMappingURL=MonitorTemplate.js.map