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 Workflow from "./Workflow";
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 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 WorkflowStatus from "../../Types/Workflow/WorkflowStatus";
import { Column, Entity, Index, JoinColumn, ManyToOne } from "typeorm";
let WorkflowLog = class WorkflowLog extends BaseModel {
    constructor() {
        super(...arguments);
        this.project = undefined;
        this.projectId = undefined;
        this.workflow = undefined;
        this.workflowId = undefined;
        this.logs = undefined;
        this.workflowStatus = undefined;
        this.startedAt = undefined;
        this.completedAt = undefined;
        this.resumeAt = undefined;
        /*
         * Internal. Serialized execution state (pending steps, executed steps and
         * accumulated component return values) used to resume a workflow run after a
         * Sleep step. Never exposed via the API.
         */
        this.resumeData = undefined;
        this.deletedByUser = undefined;
        this.deletedByUserId = undefined;
    }
};
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        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)
], WorkflowLog.prototype, "project", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        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)
], WorkflowLog.prototype, "projectId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        manyToOneRelationColumn: "workflowId",
        type: TableColumnType.Entity,
        modelType: Workflow,
        title: "Workflow",
        description: "Workflow this logs belong to",
    }),
    ManyToOne(() => {
        return Workflow;
    }, {
        eager: false,
        nullable: true,
        onDelete: "CASCADE",
        orphanedRowAction: "nullify",
    }),
    JoinColumn({ name: "workflowId" }),
    __metadata("design:type", Workflow)
], WorkflowLog.prototype, "workflow", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    Index(),
    TableColumn({
        type: TableColumnType.ObjectID,
        required: true,
        canReadOnRelationQuery: true,
        title: "Workflow ID",
        description: "ID of Workflow this logs belong to",
    }),
    Column({
        type: ColumnType.ObjectID,
        nullable: false,
        transformer: ObjectID.getDatabaseTransformer(),
    }),
    __metadata("design:type", ObjectID)
], WorkflowLog.prototype, "workflowId", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        required: false,
        type: TableColumnType.VeryLongText,
        title: "Logs",
        description: "Logs",
    }),
    Column({
        nullable: false,
        type: ColumnType.VeryLongText,
    }),
    __metadata("design:type", String)
], WorkflowLog.prototype, "logs", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        required: true,
        type: TableColumnType.WorkflowStatus,
        title: "Workflow Status",
        description: "Status of this workflow",
    }),
    Column({
        nullable: false,
        type: ColumnType.ShortText,
    }),
    __metadata("design:type", String)
], WorkflowLog.prototype, "workflowStatus", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Date,
        title: "Started At",
        description: "When did this workflow start",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], WorkflowLog.prototype, "startedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Date,
        title: "Completed At",
        description: "When did this workflow complete",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], WorkflowLog.prototype, "completedAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        update: [],
    }),
    TableColumn({
        type: TableColumnType.Date,
        title: "Resume At",
        description: "When this workflow run is scheduled to resume after a Sleep step (only set while the run is Waiting).",
    }),
    Column({
        type: ColumnType.Date,
        nullable: true,
        unique: false,
    }),
    __metadata("design:type", Date)
], WorkflowLog.prototype, "resumeAt", void 0);
__decorate([
    ColumnAccessControl({
        create: [],
        read: [],
        update: [],
    }),
    TableColumn({
        required: false,
        isDefaultValueColumn: false,
        type: TableColumnType.JSON,
        title: "Resume Data",
        description: "Internal serialized execution state used to resume a workflow run after a Sleep step.",
    }),
    Column({
        type: ColumnType.JSON,
        nullable: true,
    }),
    __metadata("design:type", Object)
], WorkflowLog.prototype, "resumeData", 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)
], WorkflowLog.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)
], WorkflowLog.prototype, "deletedByUserId", void 0);
WorkflowLog = __decorate([
    EnableDocumentation(),
    CanAccessIfCanReadOn("workflow"),
    TenantColumn("projectId"),
    TableAccessControl({
        create: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.CreateWorkflowLog,
        ],
        read: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.ProjectMember,
            Permission.Viewer,
            Permission.WorkflowAdmin,
            Permission.WorkflowMember,
            Permission.WorkflowViewer,
            Permission.ReadWorkflowLog,
        ],
        delete: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.DeleteWorkflowLog,
        ],
        update: [
            Permission.ProjectOwner,
            Permission.ProjectAdmin,
            Permission.EditWorkflowLog,
        ],
    }),
    CrudApiEndpoint(new Route("/workflow-log")),
    OwnedThrough("workflowId", Workflow),
    Entity({
        name: "WorkflowLog",
    }),
    TableMetadata({
        tableName: "WorkflowLog",
        singularName: "Workflow Log",
        pluralName: "Workflow Logs",
        icon: IconProp.Logs,
        tableDescription: "Logs of the workflows executed",
    }),
    Index(["workflowStatus", "createdAt"]) // Worker sweep for scheduled/timed-out runs
], WorkflowLog);
export default WorkflowLog;
//# sourceMappingURL=WorkflowLog.js.map