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 Incident from "./Incident";
import IncidentSlaRule from "./IncidentSlaRule";
import Project from "./Project";
import User from "./User";
import BaseModel from "./DatabaseBaseModel/DatabaseBaseModel";
import Route from "../../Types/API/Route";
import ColumnAccessControl from "../../Types/Database/AccessControl/ColumnAccessControl";
import OwnedThrough from "../../Types/Database/AccessControl/OwnedThrough";
import TableAccessControl from "../../Types/Database/AccessControl/TableAccessControl";
import CanAccessIfCanReadOn from "../../Types/Database/CanAccessIfCanReadOn";
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 IncidentSlaStatus from "../../Types/Incident/IncidentSlaStatus";
import ObjectID from "../../Types/ObjectID";
import Permission from "../../Types/Permission";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let IncidentSla = class IncidentSla extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        // Incident Relation
        this.incident = undefined;
        this.incidentId = undefined;
        // SLA Rule Relation
        this.incidentSlaRule = undefined;
        this.incidentSlaRuleId = undefined;
        // SLA Deadlines
        this.responseDeadline = undefined;
        this.resolutionDeadline = undefined;
        // SLA Status
        this.status = undefined;
        // Actual Response/Resolution Times
        this.respondedAt = undefined;
        this.resolvedAt = undefined;
        // Reminder Tracking
        this.lastInternalNoteReminderSentAt = undefined;
        this.lastPublicNoteReminderSentAt = undefined;
        this.breachNotificationSentAt = undefined;
        // SLA Start Time (when SLA tracking began)
        this.slaStartedAt = undefined;
        // Created By / Deleted By User Relations
        this.createdByUser = undefined;
        this.createdByUserId = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        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)
], IncidentSla.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        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)
], IncidentSla.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "incidentId",
        type: TableColumnType.Entity,
        modelType: Incident,
        title: "Incident",
        description: "The incident this SLA record is tracking",
    }),
    ManyToOne(() => {
        return Incident;
    }, {
        eager: false,
        nullable: false,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "incidentId" }),
    __metadata("design:type", Incident)
], IncidentSla.prototype, "incident", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Incident ID",
        description: "ID of the incident this SLA record is tracking",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], IncidentSla.prototype, "incidentId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "incidentSlaRuleId",
        type: TableColumnType.Entity,
        modelType: IncidentSlaRule,
        title: "SLA Rule",
        description: "The SLA rule that was applied to this incident",
    }),
    ManyToOne(() => {
        return IncidentSlaRule;
    }, {
        eager: false,
        nullable: false,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "incidentSlaRuleId" }),
    __metadata("design:type", IncidentSlaRule)
], IncidentSla.prototype, "incidentSlaRule", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "SLA Rule ID",
        description: "ID of the SLA rule that was applied to this incident",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], IncidentSla.prototype, "incidentSlaRuleId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Response Deadline",
        description: "The deadline by which the incident must be acknowledged to meet the SLA",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "responseDeadline", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Resolution Deadline",
        description: "The deadline by which the incident must be resolved to meet the SLA",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "resolutionDeadline", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ShortText,
        required: true,
        title: "Status",
        description: "Current SLA status (On Track, At Risk, Breached, Met)",
        defaultValue: IncidentSlaStatus.OnTrack,
        isDefaultValueColumn: true,
    }),
    Column({
        type: ColumnType.ShortText,
        nullable: false,
        default: IncidentSlaStatus.OnTrack,
    }),
    __metadata("design:type", String)
], IncidentSla.prototype, "status", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Responded At",
        description: "The actual time when the incident was acknowledged",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "respondedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Resolved At",
        description: "The actual time when the incident was resolved",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "resolvedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Last Internal Note Reminder Sent At",
        description: "The last time an internal note reminder was sent",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "lastInternalNoteReminderSentAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Last Public Note Reminder Sent At",
        description: "The last time a public note reminder was sent",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "lastPublicNoteReminderSentAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        required: false,
        title: "Breach Notification Sent At",
        description: "The time when breach notification was sent to incident owners",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "breachNotificationSentAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.Date,
        required: true,
        title: "SLA Started At",
        description: "The time when SLA tracking started (usually the incident declaredAt time)",
    }),
    Column({
        type: ColumnType.Date,
        nullable: false,
    }),
    __metadata("design:type", Date)
], IncidentSla.prototype, "slaStartedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        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)
], IncidentSla.prototype, "createdByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        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)
], IncidentSla.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)
], IncidentSla.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)
], IncidentSla.prototype, "deletedByUserId", void 0);
IncidentSla = __decorate([
    EnableDocumentation(),
    CanAccessIfCanReadOn("incident"),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateIncidentSla,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.IncidentAdmin,
            Permission.IncidentMember,
            Permission.IncidentViewer,
            Permission.ReadIncidentSla,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteIncidentSla,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditIncidentSla,
        ],
    }),
    CrudApiEndpoint(new Route("/incident-sla")),
    OwnedThrough("incidentId", Incident),
    Entity({
        name: "IncidentSla",
    }),
    EnableWorkflow({
        create: true,
        delete: true,
        update: true,
        read: true,
    }),
    TableMetadata({
        tableName: "IncidentSla",
        singularName: "Incident SLA",
        pluralName: "Incident SLAs",
        icon: IconProp.Clock,
        tableDescription: "Track SLA status and deadlines for incidents",
    })
], IncidentSla);
export default IncidentSla;
//# sourceMappingURL=IncidentSla.js.map