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 File from "./File";
import Project from "./Project";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import { PlanType } from "../../Types/Billing/SubscriptionPlan";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import TableBillingAccessControl from "../../Types/Database/AccessControl/TableBillingAccessControl";
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 IsPermissionsIf from "../../Types/Database/IsPermissionsIf";
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 ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import Version from "../../Types/Version";
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, ManyToOne, } from "typeorm";
import Label from "./Label";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import EnableWorkflow from "../../Types/Database/EnableWorkflow";
export var ProbeConnectionStatus;
(function (ProbeConnectionStatus) {
    ProbeConnectionStatus["Connected"] = "connected";
    ProbeConnectionStatus["Disconnected"] = "disconnected";
})(ProbeConnectionStatus || (ProbeConnectionStatus = {}));
let Probe = class Probe extends BaseModel {
    constructor() {
        super(...arguments);
        this.key = undefined;
        this.name = undefined;
        this.description = undefined;
        this.slug = undefined;
        this.probeVersion = undefined;
        this.lastAlive = undefined;
        this.iconFile = undefined;
        this.iconFileId = undefined;
        this.project = undefined;
        this.projectId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.isGlobalProbe = undefined;
        this.shouldAutoEnableProbeOnNewMonitors = undefined;
        this.connectionStatus = undefined;
        this.labels = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.ProjectOwner, Permission.ProjectAdmin],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectProbe,
        ],
    }),
    TableColumn({
        required: true,
        unique: true,
        type: TableColumnType.ShortText,
    }),
    Column({
        type: ColumnType.ShortText,
        nullable: false,
        unique: true,
    }),
    __metadata("design:type", String)
], Probe.prototype, "key", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectProbe,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.Name,
        canReadOnRelationQuery: true,
        example: "US East Coast Probe",
    }),
    Column({
        nullable: false,
        type: ColumnType.Name,
        length: ColumnLength.Name,
    }),
    __metadata("design:type", String)
], Probe.prototype, "name", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectProbe,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Name,
        example: "Monitors services from the US East Coast region",
    }),
    Column({
        nullable: true,
        type: ColumnType.Name,
        length: ColumnLength.Name,
    }),
    __metadata("design:type", String)
], Probe.prototype, "description", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        required: true,
        unique: true,
        type: TableColumnType.Slug,
        computed: true,
        title: "Slug",
        description: "Friendly globally unique name for your object",
        example: "us-east-coast-probe",
    }),
    Column({
        nullable: false,
        type: ColumnType.Slug,
        length: ColumnLength.Slug,
    }),
    __metadata("design:type", String)
], Probe.prototype, "slug", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.Public],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectProbe,
        ],
    }),
    TableColumn({ required: true, type: TableColumnType.Version }),
    Column({
        nullable: false,
        type: ColumnType.Version,
        length: ColumnLength.Version,
        transformer: Version.getDatabaseTransformer(),
    }),
    __metadata("design:type", Version)
], Probe.prototype, "probeVersion", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectProbe,
        ],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        type: TableColumnType.Date,
        canReadOnRelationQuery: true,
    }),
    Column({
        nullable: true,
        type: ColumnType.Date,
    }),
    __metadata("design:type", Date)
], Probe.prototype, "lastAlive", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectStatusPage,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectStatusPage,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectStatusPage,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "iconFileId",
        type: TableColumnType.Entity,
        modelType: File,
        title: "Icon",
        description: "Probe Icon",
    }),
    ManyToOne(() => {
        return File;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "delete",
    }),
    JoinColumn({ name: "iconFileId" }),
    __metadata("design:type", File)
], Probe.prototype, "iconFile", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectStatusPage,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectStatusPage,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectStatusPage,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Icon",
        description: "Probe Page Icon File ID",
        canReadOnRelationQuery: true,
        example: "c3d4e5f6-a7b8-9012-cdef-123456789012",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], Probe.prototype, "iconFileId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Entity,
        required: false,
        modelType: Project,
    }),
    ManyToOne(() => {
        return Project;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], Probe.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.Public],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        canReadOnRelationQuery: true,
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], Probe.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({ type: TableColumnType.Entity, modelType: User }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], Probe.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)",
        example: "d4e5f6a7-b8c9-0123-def1-234567890123",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], Probe.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.ProjectOwner],
        update: [],
    }),
    TableColumn({ type: TableColumnType.Entity, modelType: User }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], Probe.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [Permission.ProjectOwner],
        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: "e5f6a7b8-c9d0-1234-ef12-345678901234",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], Probe.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        canReadOnRelationQuery: true,
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], Probe.prototype, "isGlobalProbe", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectStatusPage,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectStatusPage,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectStatusPage,
        ],
    }),
    TableColumn({
        isDefaultValueColumn: true,
        required: true,
        title: "Auto Enable Probe",
        description: "Auto Enable Probe on New Monitors",
        type: TableColumnType.Boolean,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], Probe.prototype, "shouldAutoEnableProbeOnNewMonitors", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectStatusPage,
        ],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        title: "Connection Status",
        description: "Connection Status of the Probe",
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
    }),
    Column({
        type: ColumnType.ShortText,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", String)
], Probe.prototype, "connectionStatus", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectStatusPage,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectStatusPage,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectStatusPage,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Label,
        title: "Labels",
        description: "Relation to Labels Array where this object is categorized in.",
    }),
    ManyToMany(() => {
        return Label;
    }, { eager: false }),
    JoinTable({
        name: "ProbeLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "probeId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], Probe.prototype, "labels", void 0);
Probe = __decorate([
    EnableDocumentation(),
    EnableWorkflow({
        read: true,
    }),
    TableBillingAccessControl({
        create: PlanType.Growth,
        read: PlanType.Free,
        update: PlanType.Growth,
        delete: PlanType.Free,
    }),
    IsPermissionsIf(Permission.Public, "projectId", null),
    TenantColumn("projectId"),
    CrudApiEndpoint(new Route("/probe")),
    AccessControlColumn("labels"),
    SlugifyColumn("name", "slug"),
    Entity({
        name: "Probe",
    }),
    TableMetadata({
        tableName: "Probe",
        singularName: "Probe",
        pluralName: "Probes",
        icon: IconProp.Settings,
        tableDescription: "Manages custom probes. Deploy probes anywhere in the world and connect it to your project.",
    }),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.CreateProjectProbe,
        ],
        read: [
            Permission.Public,
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.SettingsViewer,
            Permission.ReadProjectProbe,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.DeleteProjectProbe,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.SettingsAdmin,
            Permission.SettingsMember,
            Permission.EditProjectProbe,
        ],
    })
], Probe);
export default Probe;
//# sourceMappingURL=Probe.js.map