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 AlertSeverity from "./AlertSeverity";
import AlertState from "./AlertState";
import Label from "./Label";
import OnCallDutyPolicy from "./OnCallDutyPolicy";
import Project from "./Project";
import Team from "./Team";
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 MultiTenentQueryAllowed from "../../Types/Database/MultiTenentQueryAllowed";
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, JoinTable, ManyToMany, ManyToOne, } from "typeorm";
import AlertGroupingRule from "./AlertGroupingRule";
let AlertEpisode = class AlertEpisode extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.title = undefined;
        this.description = undefined;
        this.episodeNumber = undefined;
        this.episodeNumberWithPrefix = undefined;
        this.currentAlertState = undefined;
        this.currentAlertStateId = undefined;
        this.alertSeverity = undefined;
        this.alertSeverityId = undefined;
        this.rootCause = undefined;
        this.lastAlertAddedAt = undefined;
        this.resolvedAt = undefined;
        this.allAlertsResolvedAt = undefined;
        this.assignedToUser = undefined;
        this.assignedToUserId = undefined;
        this.assignedToTeam = undefined;
        this.assignedToTeamId = undefined;
        this.alertGroupingRule = undefined;
        this.alertGroupingRuleId = undefined;
        this.onCallDutyPolicies = undefined;
        this.isOnCallPolicyExecuted = undefined;
        this.alertCount = undefined;
        this.titleTemplate = undefined;
        this.descriptionTemplate = undefined;
        this.isManuallyCreated = undefined;
        this.labels = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.isOwnerNotifiedOfEpisodeCreation = undefined;
        this.groupingKey = undefined;
        this.remediationNotes = undefined;
        this.postUpdatesToWorkspaceChannels = undefined;
        this.isPrivate = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        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)
], AlertEpisode.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        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)
], AlertEpisode.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.LongText,
        canReadOnRelationQuery: true,
        title: "Title",
        description: "Title of this alert episode",
    }),
    Column({
        nullable: false,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "title", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Markdown,
        title: "Description",
        description: "Description of this alert episode. This is in markdown format.",
    }),
    Column({
        nullable: true,
        type: ColumnType.Markdown,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "description", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        type: TableColumnType.Number,
        title: "Episode Number",
        description: "Auto-incrementing episode number per project",
    }),
    Column({
        type: ColumnType.Number,
        nullable: true,
    }),
    __metadata("design:type", Number)
], AlertEpisode.prototype, "episodeNumber", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    TableColumn({
        isDefaultValueColumn: false,
        required: false,
        type: TableColumnType.ShortText,
        title: "Episode Number With Prefix",
        description: "Episode number with prefix (e.g., 'AE-42' or '#42')",
        computed: true,
    }),
    Column({
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
        nullable: true,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "episodeNumberWithPrefix", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "currentAlertStateId",
        type: TableColumnType.Entity,
        modelType: AlertState,
        title: "Current Alert State",
        description: "Current state of this episode. Is the episode acknowledged? or resolved?",
    }),
    ManyToOne(() => {
        return AlertState;
    }, {
        eager: false,
        nullable: true,
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "currentAlertStateId" }),
    __metadata("design:type", AlertState)
], AlertEpisode.prototype, "currentAlertState", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        isDefaultValueColumn: true,
        title: "Current Alert State ID",
        description: "Current Alert State ID",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], AlertEpisode.prototype, "currentAlertStateId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "alertSeverityId",
        type: TableColumnType.Entity,
        modelType: AlertSeverity,
        title: "Alert Severity",
        description: "High-water mark severity of this episode. Represents the highest severity among all member alerts.",
    }),
    ManyToOne(() => {
        return AlertSeverity;
    }, {
        eager: false,
        nullable: true,
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "alertSeverityId" }),
    __metadata("design:type", AlertSeverity)
], AlertEpisode.prototype, "alertSeverity", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Alert Severity ID",
        description: "Alert Severity ID",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], AlertEpisode.prototype, "alertSeverityId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        type: TableColumnType.Markdown,
        required: false,
        isDefaultValueColumn: false,
        title: "Root Cause",
        description: "User-documented root cause of this episode",
    }),
    Column({
        type: ColumnType.Markdown,
        nullable: true,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "rootCause", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Date,
        title: "Last Alert Added At",
        description: "When the last alert was added to this episode",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], AlertEpisode.prototype, "lastAlertAddedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Date,
        title: "Resolved At",
        description: "When this episode was resolved",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], AlertEpisode.prototype, "resolvedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Date,
        title: "All Alerts Resolved At",
        description: "When all alerts in this episode were first detected as resolved. Used for resolve delay calculation.",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], AlertEpisode.prototype, "allAlertsResolvedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "assignedToUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Assigned To User",
        description: "User who is assigned to this episode",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "assignedToUserId" }),
    __metadata("design:type", User)
], AlertEpisode.prototype, "assignedToUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Assigned To User ID",
        description: "User ID who is assigned to this episode",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], AlertEpisode.prototype, "assignedToUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "assignedToTeamId",
        type: TableColumnType.Entity,
        modelType: Team,
        title: "Assigned To Team",
        description: "Team that is assigned to this episode",
    }),
    ManyToOne(() => {
        return Team;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "assignedToTeamId" }),
    __metadata("design:type", Team)
], AlertEpisode.prototype, "assignedToTeam", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Assigned To Team ID",
        description: "Team ID that is assigned to this episode",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], AlertEpisode.prototype, "assignedToTeamId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "alertGroupingRuleId",
        type: TableColumnType.Entity,
        modelType: AlertGroupingRule,
        title: "Alert Grouping Rule",
        description: "The grouping rule that created this episode (null for manually created episodes)",
    }),
    ManyToOne(() => {
        return AlertGroupingRule;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "alertGroupingRuleId" }),
    __metadata("design:type", AlertGroupingRule)
], AlertEpisode.prototype, "alertGroupingRule", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Alert Grouping Rule ID",
        description: "Alert Grouping Rule ID that created this episode",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], AlertEpisode.prototype, "alertGroupingRuleId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: OnCallDutyPolicy,
        title: "On-Call Duty Policies",
        description: "List of on-call duty policies to execute for this episode.",
    }),
    ManyToMany(() => {
        return OnCallDutyPolicy;
    }, { eager: false }),
    JoinTable({
        name: "AlertEpisodeOnCallDutyPolicy",
        inverseJoinColumn: {
            name: "onCallDutyPolicyId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "alertEpisodeId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], AlertEpisode.prototype, "onCallDutyPolicies", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Boolean,
        required: true,
        isDefaultValueColumn: true,
        title: "Is On-Call Policy Executed?",
        description: "Whether the on-call policy has been executed for this episode",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], AlertEpisode.prototype, "isOnCallPolicyExecuted", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Number,
        required: true,
        isDefaultValueColumn: true,
        computed: true,
        title: "Alert Count",
        description: "Denormalized count of alerts in this episode",
        defaultValue: 0,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 0,
    }),
    __metadata("design:type", Number)
], AlertEpisode.prototype, "alertCount", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Title Template",
        description: "Template used to generate the episode title. Stored for dynamic variable updates.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "titleTemplate", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Description Template",
        description: "Template used to generate the episode description. Stored for dynamic variable updates.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "descriptionTemplate", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Boolean,
        required: true,
        isDefaultValueColumn: true,
        title: "Is Manually Created?",
        description: "Whether this episode was manually created vs auto-created by a rule",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], AlertEpisode.prototype, "isManuallyCreated", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    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: "AlertEpisodeLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "alertEpisodeId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], AlertEpisode.prototype, "labels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        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)
], AlertEpisode.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        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)
], AlertEpisode.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)
], AlertEpisode.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)
], AlertEpisode.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Boolean,
        required: true,
        isDefaultValueColumn: true,
        title: "Are Owners Notified Of Episode Creation?",
        description: "Are owners notified when this episode is created?",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], AlertEpisode.prototype, "isOwnerNotifiedOfEpisodeCreation", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.LongText,
        required: false,
        title: "Grouping Key",
        description: "Key used for grouping alerts into this episode. Generated from groupByFields of the matching rule.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "groupingKey", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        type: TableColumnType.Markdown,
        required: false,
        isDefaultValueColumn: false,
        title: "Remediation Notes",
        description: "User-documented remediation steps and notes for this episode",
    }),
    Column({
        type: ColumnType.Markdown,
        nullable: true,
    }),
    __metadata("design:type", String)
], AlertEpisode.prototype, "remediationNotes", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    TableColumn({
        type: TableColumnType.JSON,
        required: false,
        isDefaultValueColumn: false,
        title: "Post Updates to Workspace Channels",
        description: "Workspace channels to post episode updates to (e.g., Slack, Microsoft Teams)",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Array)
], AlertEpisode.prototype, "postUpdatesToWorkspaceChannels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    Index(),
    TableColumn({
        isDefaultValueColumn: true,
        type: TableColumnType.Boolean,
        title: "Is Private?",
        description: "If true, this alert episode is only visible to its owners (users in 'owner users' and members of 'owner teams'), project admins, and project owners.",
        defaultValue: false,
    }),
    Column({
        type: ColumnType.Boolean,
        default: false,
        nullable: true,
    }),
    __metadata("design:type", Boolean)
], AlertEpisode.prototype, "isPrivate", void 0);
AlertEpisode = __decorate([
    EnableDocumentation(),
    AccessControlColumn("labels"),
    MultiTenentQueryAllowed(true),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.CreateAlertEpisode,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.AlertViewer,
            Permission.ReadAlertEpisode,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.DeleteAlertEpisode,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.AlertAdmin,
            Permission.AlertMember,
            Permission.EditAlertEpisode,
        ],
    }),
    CrudApiEndpoint(new Route("/alert-episode")),
    Entity({
        name: "AlertEpisode",
    }),
    EnableWorkflow({
        create: true,
        delete: true,
        update: true,
        read: true,
    }),
    TableMetadata({
        tableName: "AlertEpisode",
        singularName: "Alert Episode",
        pluralName: "Alert Episodes",
        icon: IconProp.Layers,
        tableDescription: "Manage alert episodes (groups of related alerts) for your project",
        enableRealtimeEventsOn: {
            create: true,
            update: true,
            delete: true,
        },
    })
], AlertEpisode);
export default AlertEpisode;
//# sourceMappingURL=AlertEpisode.js.map