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 IncidentRole from "./IncidentRole";
import IncidentSeverity from "./IncidentSeverity";
import Label from "./Label";
import Monitor from "./Monitor";
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 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 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";
let IncidentGroupingRule = class IncidentGroupingRule extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.name = undefined;
        this.description = undefined;
        this.priority = undefined;
        this.isEnabled = undefined;
        this.matchCriteria = undefined;
        // Match Criteria Fields (individual columns for form support)
        this.monitors = undefined;
        this.incidentSeverities = undefined;
        this.incidentLabels = undefined;
        this.monitorLabels = undefined;
        this.incidentTitlePattern = undefined;
        this.incidentDescriptionPattern = undefined;
        this.monitorNamePattern = undefined;
        this.monitorDescriptionPattern = undefined;
        // Group By Fields (how to group matching incidents)
        this.groupByMonitor = undefined;
        this.groupBySeverity = undefined;
        this.groupByIncidentTitle = undefined;
        this.groupByIncidentLabels = undefined;
        this.groupByMonitorLabels = undefined;
        this.enableTimeWindow = undefined;
        this.timeWindowMinutes = undefined;
        this.groupByFields = undefined;
        this.episodeTitleTemplate = undefined;
        this.episodeDescriptionTemplate = undefined;
        this.enableResolveDelay = undefined;
        this.resolveDelayMinutes = undefined;
        this.enableReopenWindow = undefined;
        this.reopenWindowMinutes = undefined;
        this.enableInactivityTimeout = undefined;
        this.inactivityTimeoutMinutes = undefined;
        this.onCallDutyPolicies = undefined;
        this.defaultAssignToUser = undefined;
        this.defaultAssignToUserId = undefined;
        this.defaultAssignToTeam = undefined;
        this.defaultAssignToTeamId = undefined;
        // Episode Configuration Fields
        this.episodeLabels = undefined;
        this.episodeOwnerUsers = undefined;
        this.episodeOwnerTeams = undefined;
        this.episodeMemberRoles = undefined;
        this.episodeMemberRoleAssignments = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.showEpisodeOnStatusPage = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        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)
], IncidentGroupingRule.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        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)
], IncidentGroupingRule.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Name",
        description: "Name of this incident grouping rule",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "name", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Description",
        description: "Description of this incident grouping rule",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "description", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.Number,
        title: "Priority",
        description: "Priority of this rule. Lower number = higher priority. Rules are evaluated in priority order.",
        defaultValue: 1,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 1,
    }),
    __metadata("design:type", Number)
], IncidentGroupingRule.prototype, "priority", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.Boolean,
        title: "Is Enabled",
        description: "Whether this rule is enabled",
        defaultValue: true,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: true,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "isEnabled", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.JSON,
        title: "Match Criteria",
        description: "JSON object defining the criteria for matching incidents to this rule",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Object)
], IncidentGroupingRule.prototype, "matchCriteria", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Monitor,
        title: "Monitors",
        description: "Only group incidents from these monitors. Leave empty to match incidents from any monitor.",
    }),
    ManyToMany(() => {
        return Monitor;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleMonitor",
        inverseJoinColumn: {
            name: "monitorId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "monitors", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: IncidentSeverity,
        title: "Incident Severities",
        description: "Only group incidents with these severities. Leave empty to match incidents of any severity.",
    }),
    ManyToMany(() => {
        return IncidentSeverity;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleIncidentSeverity",
        inverseJoinColumn: {
            name: "incidentSeverityId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "incidentSeverities", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Label,
        title: "Incident Labels",
        description: "Only group incidents that have at least one of these labels. Leave empty to match incidents regardless of incident labels.",
    }),
    ManyToMany(() => {
        return Label;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleIncidentLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "incidentLabels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Label,
        title: "Monitor Labels",
        description: "Only group incidents from monitors that have at least one of these labels. Leave empty to match incidents regardless of monitor labels.",
    }),
    ManyToMany(() => {
        return Label;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleMonitorLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "monitorLabels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Incident Title Pattern",
        description: "Regular expression pattern to match incident titles. Leave empty to match any title. Example: 'CPU.*high' matches titles containing 'CPU' followed by 'high'.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "incidentTitlePattern", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Incident Description Pattern",
        description: "Regular expression pattern to match incident descriptions. Leave empty to match any description.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "incidentDescriptionPattern", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Monitor Name Pattern",
        description: "Regular expression pattern to match monitor names. Leave empty to match any monitor name. Example: 'prod-.*' matches monitors starting with 'prod-'.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "monitorNamePattern", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Monitor Description Pattern",
        description: "Regular expression pattern to match monitor descriptions. Leave empty to match any monitor description.",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "monitorDescriptionPattern", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Group By Monitor",
        description: "When enabled, incidents from different monitors will be grouped into separate episodes. When disabled, incidents from any monitor can be grouped together.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "groupByMonitor", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Group By Incident Severity",
        description: "When enabled, incidents with different severities will be grouped into separate episodes. When disabled, incidents of any severity can be grouped together.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "groupBySeverity", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Group By Incident Title",
        description: "When enabled, incidents with different titles will be grouped into separate episodes. When disabled, incidents with any title can be grouped together.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "groupByIncidentTitle", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Group By Incident Labels",
        description: "When enabled, incidents with different sets of labels will be grouped into separate episodes (exact set match). When disabled, incident labels are ignored for grouping.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "groupByIncidentLabels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Group By Monitor Labels",
        description: "When enabled, incidents whose monitors have different sets of labels will be grouped into separate episodes (exact set match). When disabled, monitor labels are ignored for grouping.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "groupByMonitorLabels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Enable Time Window",
        description: "Enable time-based grouping. When enabled, incidents are grouped within the specified time window. When disabled, all matching incidents are grouped into a single ongoing episode regardless of time.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "enableTimeWindow", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Number,
        title: "Time Window (Minutes)",
        description: "Rolling time window in minutes. Incidents are grouped if they arrive within this gap from the last incident.",
        defaultValue: 60,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 60,
    }),
    __metadata("design:type", Number)
], IncidentGroupingRule.prototype, "timeWindowMinutes", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.JSON,
        title: "Group By Fields",
        description: "JSON object defining the fields to group incidents by (e.g., monitorId, severity)",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Object)
], IncidentGroupingRule.prototype, "groupByFields", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Episode Title Template",
        description: "Template for generating episode titles. Supports placeholders like {{incidentSeverity}}, {{monitorName}}, {{incidentTitle}}, {{incidentDescription}}",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "episodeTitleTemplate", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Episode Description Template",
        description: "Template for generating episode descriptions. Supports placeholders like {{incidentSeverity}}, {{monitorName}}, {{incidentTitle}}, {{incidentDescription}}",
    }),
    Column({
        type: ColumnType.LongText,
        nullable: true,
    }),
    __metadata("design:type", String)
], IncidentGroupingRule.prototype, "episodeDescriptionTemplate", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Enable Resolve Delay",
        description: "Enable grace period before auto-resolving episode after all incidents resolve. Helps prevent rapid state changes during incident flapping.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "enableResolveDelay", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Number,
        title: "Resolve Delay (Minutes)",
        description: "Grace period in minutes before auto-resolving an episode after all incidents are resolved",
        defaultValue: 0,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 0,
    }),
    __metadata("design:type", Number)
], IncidentGroupingRule.prototype, "resolveDelayMinutes", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Enable Reopen Window",
        description: "Enable reopening recently resolved episodes instead of creating new ones. Useful when related issues recur shortly after resolution.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "enableReopenWindow", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Number,
        title: "Reopen Window (Minutes)",
        description: "Time window in minutes to reopen a recently resolved episode instead of creating a new one",
        defaultValue: 0,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 0,
    }),
    __metadata("design:type", Number)
], IncidentGroupingRule.prototype, "reopenWindowMinutes", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Boolean,
        title: "Enable Inactivity Timeout",
        description: "Enable auto-resolving episodes after a period of inactivity. Helps automatically close episodes when no new incidents arrive.",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "enableInactivityTimeout", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Number,
        title: "Inactivity Timeout (Minutes)",
        description: "Time in minutes after which an inactive episode will be auto-resolved",
        defaultValue: 60,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        default: 60,
    }),
    __metadata("design:type", Number)
], IncidentGroupingRule.prototype, "inactivityTimeoutMinutes", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: OnCallDutyPolicy,
        title: "On-Call Duty Policies",
        description: "List of on-call duty policies to execute for episodes created by this rule.",
    }),
    ManyToMany(() => {
        return OnCallDutyPolicy;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleOnCallDutyPolicy",
        inverseJoinColumn: {
            name: "onCallDutyPolicyId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "onCallDutyPolicies", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "defaultAssignToUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Default Assign To User",
        description: "Default user to assign episodes created by this rule",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "defaultAssignToUserId" }),
    __metadata("design:type", User)
], IncidentGroupingRule.prototype, "defaultAssignToUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Default Assign To User ID",
        description: "Default User ID to assign episodes created by this rule",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], IncidentGroupingRule.prototype, "defaultAssignToUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "defaultAssignToTeamId",
        type: TableColumnType.Entity,
        modelType: Team,
        title: "Default Assign To Team",
        description: "Default team to assign episodes created by this rule",
    }),
    ManyToOne(() => {
        return Team;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "defaultAssignToTeamId" }),
    __metadata("design:type", Team)
], IncidentGroupingRule.prototype, "defaultAssignToTeam", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: false,
        title: "Default Assign To Team ID",
        description: "Default Team ID to assign episodes created by this rule",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], IncidentGroupingRule.prototype, "defaultAssignToTeamId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Label,
        title: "Episode Labels",
        description: "Labels to automatically apply to episodes created by this rule.",
    }),
    ManyToMany(() => {
        return Label;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleEpisodeLabel",
        inverseJoinColumn: {
            name: "labelId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "episodeLabels", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: User,
        title: "Episode Owner Users",
        description: "Users to automatically add as owners to episodes created by this rule.",
    }),
    ManyToMany(() => {
        return User;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleEpisodeOwnerUser",
        inverseJoinColumn: {
            name: "userId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "episodeOwnerUsers", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: Team,
        title: "Episode Owner Teams",
        description: "Teams to automatically add as owners to episodes created by this rule.",
    }),
    ManyToMany(() => {
        return Team;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleEpisodeOwnerTeam",
        inverseJoinColumn: {
            name: "teamId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "episodeOwnerTeams", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.EntityArray,
        modelType: IncidentRole,
        title: "Episode Member Roles",
        description: "Incident roles to display in the episode members form. Select the roles that can be assigned to episode members.",
    }),
    ManyToMany(() => {
        return IncidentRole;
    }, { eager: false }),
    JoinTable({
        name: "IncidentGroupingRuleEpisodeMemberRole",
        inverseJoinColumn: {
            name: "incidentRoleId",
            referencedColumnName: "_id",
        },
        joinColumn: {
            name: "incidentGroupingRuleId",
            referencedColumnName: "_id",
        },
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "episodeMemberRoles", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.JSON,
        title: "Episode Member Role Assignments",
        description: "Users with specific incident roles to automatically add as members to episodes created by this rule. Each assignment includes a user ID and an incident role ID.",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Array)
], IncidentGroupingRule.prototype, "episodeMemberRoleAssignments", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        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)
], IncidentGroupingRule.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        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)
], IncidentGroupingRule.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)
], IncidentGroupingRule.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)
], IncidentGroupingRule.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    Index(),
    TableColumn({
        required: true,
        type: TableColumnType.Boolean,
        title: "Show Episodes on Status Page",
        description: "Should episodes created by this rule be shown on the status page?",
        defaultValue: false,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], IncidentGroupingRule.prototype, "showEpisodeOnStatusPage", void 0);
IncidentGroupingRule = __decorate([
    EnableDocumentation(),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentGroupingRule,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentGroupingRule,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteIncidentGroupingRule,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentGroupingRule,
        ],
    }),
    CrudApiEndpoint(new Route("/incident-grouping-rule")),
    Entity({
        name: "IncidentGroupingRule",
    }),
    EnableWorkflow({
        create: true,
        delete: true,
        update: true,
        read: true,
    }),
    TableMetadata({
        tableName: "IncidentGroupingRule",
        singularName: "Incident Grouping Rule",
        pluralName: "Incident Grouping Rules",
        icon: IconProp.Layers,
        tableDescription: "Configure rules for automatically grouping related incidents into episodes",
    })
], IncidentGroupingRule);
export default IncidentGroupingRule;
//# sourceMappingURL=IncidentGroupingRule.js.map