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 Alert from "./Alert";
import Incident from "./Incident";
import Project from "./Project";
import Runbook from "./Runbook";
import ScheduledMaintenance from "./ScheduledMaintenance";
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 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 RunbookExecutionStatus from "../../Types/Runbook/RunbookExecutionStatus";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let RunbookExecution = class RunbookExecution extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.runbook = undefined;
        this.runbookId = undefined;
        this.runbookNameSnapshot = undefined;
        this.status = undefined;
        this.stepExecutions = undefined;
        this.incident = undefined;
        this.incidentId = undefined;
        this.alert = undefined;
        this.alertId = undefined;
        this.scheduledMaintenance = undefined;
        this.scheduledMaintenanceId = undefined;
        this.triggeredByUser = undefined;
        this.triggeredByUserId = undefined;
        this.startedAt = undefined;
        this.completedAt = undefined;
        this.failureReason = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        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)
], RunbookExecution.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        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)
], RunbookExecution.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "runbookId",
        type: TableColumnType.Entity,
        modelType: Runbook,
        title: "Runbook",
        description: "Runbook that this execution belongs to.",
    }),
    ManyToOne(() => {
        return Runbook;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "runbookId" }),
    __metadata("design:type", Runbook)
], RunbookExecution.prototype, "runbook", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Runbook ID",
        description: "ID of the Runbook this execution belongs to.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RunbookExecution.prototype, "runbookId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "Runbook Name Snapshot",
        description: "Name of the runbook at the time this execution was created (preserved even if the runbook is later renamed or deleted).",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], RunbookExecution.prototype, "runbookNameSnapshot", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.ShortText,
        title: "Status",
        description: "Current status of this runbook execution.",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
        length: ColumnLength.ShortText,
    }),
    __metadata("design:type", String)
], RunbookExecution.prototype, "status", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.JSON,
        title: "Step Executions",
        description: "Per-step execution state. Each entry mirrors a step from the runbook with status, output, and timestamps.",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Array)
], RunbookExecution.prototype, "stepExecutions", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "incidentId",
        type: TableColumnType.Entity,
        modelType: Incident,
        title: "Incident",
        description: "Incident that this runbook execution is associated with (if any).",
    }),
    ManyToOne(() => {
        return Incident;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "incidentId" }),
    __metadata("design:type", Incident)
], RunbookExecution.prototype, "incident", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Incident ID",
        description: "ID of the incident that triggered or hosts this runbook execution.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RunbookExecution.prototype, "incidentId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "alertId",
        type: TableColumnType.Entity,
        modelType: Alert,
        title: "Alert",
        description: "Alert that this runbook execution is associated with (if any).",
    }),
    ManyToOne(() => {
        return Alert;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "alertId" }),
    __metadata("design:type", Alert)
], RunbookExecution.prototype, "alert", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Alert ID",
        description: "ID of the alert that triggered or hosts this runbook execution.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RunbookExecution.prototype, "alertId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "scheduledMaintenanceId",
        type: TableColumnType.Entity,
        modelType: ScheduledMaintenance,
        title: "Scheduled Maintenance",
        description: "Scheduled maintenance event that this runbook execution is associated with (if any).",
    }),
    ManyToOne(() => {
        return ScheduledMaintenance;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "scheduledMaintenanceId" }),
    __metadata("design:type", ScheduledMaintenance)
], RunbookExecution.prototype, "scheduledMaintenance", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Scheduled Maintenance ID",
        description: "ID of the scheduled maintenance event that triggered this runbook execution.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RunbookExecution.prototype, "scheduledMaintenanceId", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "triggeredByUserId",
        type: TableColumnType.Entity,
        modelType: User,
        title: "Triggered by User",
        description: "User who triggered this runbook execution (if any).",
    }),
    ManyToOne(() => {
        return User;
    }, {
        eager: false,
        nullable: true,
        onDelete: "SET NULL",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "triggeredByUserId" }),
    __metadata("design:type", User)
], RunbookExecution.prototype, "triggeredByUser", void 0);
__decorate([
    ColumnAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.ObjectID,
        title: "Triggered by User ID",
        description: "ID of the User who triggered this runbook execution.",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: true,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], RunbookExecution.prototype, "triggeredByUserId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        title: "Started At",
        description: "Time at which this runbook execution started.",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], RunbookExecution.prototype, "startedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    TableColumn({
        type: TableColumnType.Date,
        title: "Completed At",
        description: "Time at which this runbook execution completed.",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
    }),
    __metadata("design:type", Date)
], RunbookExecution.prototype, "completedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.LongText,
        title: "Failure Reason",
        description: "Reason this runbook execution failed (if it did).",
    }),
    Column({
        nullable: true,
        type: ColumnType.LongText,
        length: ColumnLength.LongText,
    }),
    __metadata("design:type", String)
], RunbookExecution.prototype, "failureReason", 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)
], RunbookExecution.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)
], RunbookExecution.prototype, "deletedByUserId", void 0);
RunbookExecution = __decorate([
    EnableDocumentation(),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateRunbookExecution,
            Permission.ProjectMember,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.RunbookAdmin,
            Permission.RunbookMember,
            Permission.RunbookViewer,
            Permission.ReadRunbookExecution,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteRunbookExecution,
            Permission.RunbookAdmin,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditRunbookExecution,
            Permission.RunbookAdmin,
        ],
    }),
    CrudApiEndpoint(new Route("/runbook-execution")),
    Entity({
        name: "RunbookExecution",
    }),
    TableMetadata({
        tableName: "RunbookExecution",
        singularName: "Runbook Execution",
        pluralName: "Runbook Executions",
        icon: IconProp.Play,
        tableDescription: "A single run of a Runbook.",
    })
], RunbookExecution);
export default RunbookExecution;
//# sourceMappingURL=RunbookExecution.js.map