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 Project from "./Project";
import User from "./User";
import Team from "./Team";
import Route from "../../Types/API/Route";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import OwnedThrough from "../../Types/Database/AccessControl/OwnedThrough";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import CanAccessIfCanReadOn from "../../Types/Database/CanAccessIfCanReadOn";
import ColumnLength from "../../Types/Database/ColumnLength";
import ColumnType from "../../Types/Database/ColumnType";
import CrudApiEndpoint from "../../Types/Database/CrudApiEndpoint";
import EnableDocumentation from "../../Types/Database/EnableDocumentation";
import TableColumn from "../../Types/Database/TableColumn";
import TableColumnType from "../../Types/Database/TableColumnType";
import TableMetadata from "../../Types/Database/TableMetadata";
import TenantColumn from "../../Types/Database/TenantColumn";
import IconProp from "../../Types/Icon/IconProp";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import ServiceType from "../../Types/Telemetry/ServiceType";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
import DatabaseBaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Service from "./Service";
import Host from "./Host";
import DockerHost from "./DockerHost";
import KubernetesCluster from "./KubernetesCluster";
import ServerlessFunction from "./ServerlessFunction";
import CloudResource from "./CloudResource";
import RumApplication from "./RumApplication";
let TelemetryException = class TelemetryException extends DatabaseBaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        /*
         * primaryEntityId is polymorphic (disambiguated by primaryEntityType, mirroring the
         * ClickHouse ExceptionInstance rows): it can be a real Service, a Host /
         * DockerHost / KubernetesCluster id, or the projectId for unattributed
         * (Unknown) telemetry. There is intentionally NO @ManyToOne(Service)
         * relation — a Service join would only resolve OpenTelemetry rows and
         * silently null out everything else. The read side resolves primaryEntityId +
         * primaryEntityType to a resource per type (TelemetryServiceUtil) instead.
         */
        this.primaryEntityId = undefined;
        this.primaryEntityType = undefined;
        this.message = undefined;
        this.stackTrace = undefined;
        this.exceptionType = undefined;
        this.fingerprint = undefined;
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
        this.markedAsResolvedAt = undefined;
        this.markedAsArchivedAt = undefined;
        this.firstSeenAt = undefined;
        this.lastSeenAt = undefined;
        // assign to.
        this.assignToUser = undefined;
        this.assignToUserId = undefined;
        // assign to team.
        // assign to.
        this.assignToTeam = undefined;
        this.assignToTeamId = undefined;
        // mark as resolved by.
        this.markedAsResolvedByUser = undefined;
        this.markedAsResolvedByUserId = undefined;
        // Mark as archived by.
        this.markedAsArchivedByUser = undefined;
        this.markedAsArchivedByUserId = undefined;
        this.isResolved = undefined;
        this.isArchived = undefined;
        this.occuranceCount = undefined;
        this.firstSeenInRelease = undefined;
        this.lastSeenInRelease = undefined;
        this.environment = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "projectId",
        type: TableColumnType.Entity,
        modelType: Project,
        title: "Project",
        description: "Relation to Project Resource in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    ManyToOne(() => {
        return Project;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "projectId" }),
    __metadata("design:type", Project)
], TelemetryException.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Project ID",
        description: "ID of your OneUptime Project in which this object belongs",
        example: "5f8b9c0d-e1a2-4b3c-8d5e-6f7a8b9c0d1e",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        title: "Service ID",
        description: "ID of the resource this exception belongs to (Service / Host / DockerHost / KubernetesCluster, or the projectId for unattributed telemetry — disambiguated by primaryEntityType).",
        example: "d4e5f6a7-b8c9-0123-def1-234567890123",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "primaryEntityId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: true,
        title: "Service Type",
        description: "Resource type that produced this exception (e.g. OpenTelemetry service, Host, DockerHost, KubernetesCluster, or Unknown for unattributed telemetry).",
        example: "OpenTelemetry",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "primaryEntityType", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        canReadOnRelationQuery: false,
        title: "Exception Message",
        description: "Exception message that was thrown by the telemetry service",
        example: "NullPointerException: Cannot read property 'id' of null",
    }),
    Column({
        nullable: true,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "message", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        canReadOnRelationQuery: false,
        title: "Stack Trace",
        description: "Stack trace of the exception that was thrown by the telemetry service",
        example: "at getUserData (/app/src/services/user.js:42:15)\nat processRequest (/app/src/controllers/user.js:89:20)",
    }),
    Column({
        nullable: true,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "stackTrace", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        canReadOnRelationQuery: false,
        title: "Exception Type",
        description: "Type of the exception that was thrown by the telemetry service",
        example: "NullPointerException",
    }),
    Column({
        nullable: true,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "exceptionType", void 0);
__decorate([
    Index(),
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.ShortText,
        canReadOnRelationQuery: false,
        title: "Finger Print",
        description: "Finger print of the exception that was thrown by the telemetry service",
        example: "a8b7c6d5e4f3g2h1",
    }),
    Column({
        nullable: true,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "fingerprint", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "createdByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Created by User",
        description: "Relation to User who created this object (if this object was created by a User)",
        example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "createdByUserId" }),
    __metadata("design:type", User)
], TelemetryException.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Created by User ID",
        description: "User ID who created this object (if this object was created by a User)",
        example: "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "createdByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "deletedByUserId",
        type: TableColumnType.Entity,
        title: "Deleted by User",
        modelType: User,
        description: "Relation to User who deleted this object (if this object was deleted by a User)",
        example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "deletedByUserId" }),
    __metadata("design:type", User)
], TelemetryException.prototype, "deletedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Deleted by User ID",
        description: "User ID who deleted this object (if this object was deleted by a User)",
        example: "b2c3d4e5-f6a7-8901-bcde-f12345678901",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "deletedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Accepted Invitation At",
        description: "When did this team member accept invitation",
        example: "2025-12-12T14:30:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], TelemetryException.prototype, "markedAsResolvedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Accepted Invitation At",
        description: "When did this team member accept invitation",
        example: "2025-12-12T15:45:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], TelemetryException.prototype, "markedAsArchivedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Accepted Invitation At",
        description: "When did this team member accept invitation",
        example: "2025-12-10T08:15:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], TelemetryException.prototype, "firstSeenAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.Date,
        title: "Accepted Invitation At",
        description: "When did this team member accept invitation",
        example: "2025-12-12T16:20:00.000Z",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], TelemetryException.prototype, "lastSeenAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "assignToUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Assign to User",
        description: "Relation to User who this exception is assigned to.",
        example: "e5f6a7b8-c9d0-1234-efgh-234567890124",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "assignToUserId" }),
    __metadata("design:type", User)
], TelemetryException.prototype, "assignToUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Assign to User ID",
        description: "User ID who this exception is assigned to.",
        example: "e5f6a7b8-c9d0-1234-efgh-234567890124",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "assignToUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "assignToTeamId",
        type: TableColumnType.Entity,
        modelType: Team,
        title: "Assign to Team",
        description: "Relation to Team who this exception is assigned to.",
        example: "f6a7b8c9-d0e1-2345-fghi-345678901235",
    }),
    ManyToOne(() => {
        return Team;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "assignToTeamId" }),
    __metadata("design:type", Team)
], TelemetryException.prototype, "assignToTeam", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Assign to Team ID",
        description: "Team ID who this exception is assigned to.",
        example: "f6a7b8c9-d0e1-2345-fghi-345678901235",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "assignToTeamId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "markedAsResolvedByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Marked as Resolved By User",
        description: "Mark as resolved by User who marked this exception as resolved.",
        example: "a7b8c9d0-e1f2-3456-ghij-456789012346",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "markedAsResolvedByUserId" }),
    __metadata("design:type", User)
], TelemetryException.prototype, "markedAsResolvedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Marked as Resolved By User ID",
        description: "User ID who marked this exception as resolved.",
        example: "a7b8c9d0-e1f2-3456-ghij-456789012346",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "markedAsResolvedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        manyToOneRelationColumn: "markedAsArchivedByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Mark as Archived By User",
        description: "Mark as archived by User",
        example: "b8c9d0e1-f2a3-4567-hijk-567890123457",
    }),
    ManyToOne(() => {
        return User;
    }, {
        cascade: false,
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "markedAsArchivedByUserId" }),
    __metadata("design:type", User)
], TelemetryException.prototype, "markedAsArchivedByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Mark as Archived By User ID",
        description: "User ID who marked this exception as archived.",
        example: "b8c9d0e1-f2a3-4567-hijk-567890123457",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], TelemetryException.prototype, "markedAsArchivedByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        title: "Is Resolved",
        description: "Is this exception resolved?",
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        defaultValue: false,
        example: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], TelemetryException.prototype, "isResolved", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        title: "Is Archived",
        description: "Is this exception archived?",
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Boolean,
        defaultValue: false,
        example: false,
    }),
    Column({
        type: ColumnType.Boolean,
        nullable: false,
        unique: false,
        default: false,
    }),
    __metadata("design:type", Boolean)
], TelemetryException.prototype, "isArchived", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    Index(),
    TableColumn({
        title: "Occurances",
        description: "Number of times this exception has occurred",
        isDefaultValueColumn: true,
        required: true,
        type: TableColumnType.Number,
        defaultValue: 1,
        example: 42,
    }),
    Column({
        type: ColumnType.Number,
        nullable: false,
        unique: false,
        default: 1,
    }),
    __metadata("design:type", Number)
], TelemetryException.prototype, "occuranceCount", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        canReadOnRelationQuery: true,
        title: "First Seen In Release",
        description: "The service version / release in which this exception was first observed",
        example: "v1.2.3",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "firstSeenInRelease", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        canReadOnRelationQuery: true,
        title: "Last Seen In Release",
        description: "The most recent service version / release in which this exception was observed",
        example: "v1.4.0",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "lastSeenInRelease", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        canReadOnRelationQuery: true,
        title: "Environment",
        description: "Deployment environment from deployment.environment resource attribute",
        example: "production",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], TelemetryException.prototype, "environment", void 0);
TelemetryException = __decorate([
    EnableDocumentation(),
    CanAccessIfCanReadOn("service"),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateTelemetryException,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.TelemetryAdmin,
            Permission.TelemetryMember,
            Permission.TelemetryViewer,
            Permission.ReadTelemetryException,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteTelemetryException,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditTelemetryException,
        ],
    }),
    CrudApiEndpoint(new Route("/telemetry-exception")),
    TableMetadata({
        tableName: "TelemetryException",
        singularName: "Exception",
        pluralName: "Exceptions",
        icon: IconProp.Error,
        tableDescription: "List of all Telemetry Exceptions created for the telemetry service for this OneUptime project and it's status.",
    })
    /*
     * primaryEntityId is polymorphic (see the column below) — it may reference a
     * Service, Host, DockerHost or KubernetesCluster, or be the projectId for
     * unattributed (Unknown) telemetry. Owned scope unions ownership across all
     * of those resource types, and includeProjectScope lets in-project users
     * see the unattributed bucket (which has no owner resource).
     */
    ,
    OwnedThrough("primaryEntityId", [
        Service,
        Host,
        DockerHost,
        KubernetesCluster,
        ServerlessFunction,
        CloudResource,
        RumApplication,
    ], {
        includeProjectScope: true,
    }),
    Entity({
        name: "TelemetryException",
    }),
    Index(["projectId", "isResolved", "isArchived"]) // Exceptions dashboard counts/filters
    /*
     * Composite uniqueness on the dedup key used by the OTel traces ingest
     * batched upsert. The ingest path collapses every exception event in a
     * worker batch into a single INSERT … ON CONFLICT (projectId,
     * primaryEntityId, fingerprint) DO UPDATE statement; this index is what makes
     * that conflict target resolvable and stops two concurrent workers from
     * racing the old findOneBy + update path into duplicate rows or lost
     * occuranceCount increments.
     */
    ,
    Index(["projectId", "primaryEntityId", "fingerprint"], { unique: true })
], TelemetryException);
export default TelemetryException;
//# sourceMappingURL=TelemetryException.js.map