"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Process = void 0;
const tslib_1 = require("tslib");
const typeorm_1 = require("typeorm");
const type_graphql_1 = require("type-graphql");
const shell_1 = require("@things-factory/shell");
const process_group_1 = require("../process-group/process-group");
const auth_base_1 = require("@things-factory/auth-base");
const env_1 = require("@things-factory/env");
const ORMCONFIG = env_1.config.get('ormconfig', {});
const DATABASE_TYPE = ORMCONFIG.type;
let Process = class Process {
    constructor() {
        this.version = 1;
    }
};
tslib_1.__decorate([
    (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
    (0, type_graphql_1.Field)(type => type_graphql_1.ID, { nullable: true }),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "id", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)({ nullable: true, default: 1 }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", Number)
], Process.prototype, "version", void 0);
tslib_1.__decorate([
    (0, typeorm_1.ManyToOne)(type => shell_1.Domain),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", shell_1.Domain)
], Process.prototype, "domain", void 0);
tslib_1.__decorate([
    (0, typeorm_1.RelationId)((process) => process.domain),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "domainId", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)(),
    (0, type_graphql_1.Field)(),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "name", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)({
        nullable: true
    }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "description", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)({ nullable: true, default: 'draft' }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "state", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)({
        nullable: true,
        type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
            ? 'longtext'
            : DATABASE_TYPE == 'oracle'
                ? 'clob'
                : 'varchar'
    }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "model", void 0);
tslib_1.__decorate([
    (0, typeorm_1.Column)({
        nullable: true,
        type: DATABASE_TYPE == 'mysql' || DATABASE_TYPE == 'mariadb'
            ? 'longtext'
            : DATABASE_TYPE == 'oracle'
                ? 'clob'
                : 'varchar'
    }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "thumbnail", void 0);
tslib_1.__decorate([
    (0, typeorm_1.ManyToOne)(type => process_group_1.ProcessGroup, group => group.processes),
    (0, type_graphql_1.Field)(type => process_group_1.ProcessGroup, { nullable: true }),
    tslib_1.__metadata("design:type", process_group_1.ProcessGroup)
], Process.prototype, "group", void 0);
tslib_1.__decorate([
    (0, typeorm_1.RelationId)((process) => process.group),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "groupId", void 0);
tslib_1.__decorate([
    (0, typeorm_1.CreateDateColumn)(),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", Date)
], Process.prototype, "createdAt", void 0);
tslib_1.__decorate([
    (0, typeorm_1.UpdateDateColumn)(),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", Date)
], Process.prototype, "updatedAt", void 0);
tslib_1.__decorate([
    (0, typeorm_1.ManyToOne)(type => auth_base_1.User, {
        nullable: true
    }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", auth_base_1.User)
], Process.prototype, "creator", void 0);
tslib_1.__decorate([
    (0, typeorm_1.RelationId)((process) => process.creator),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "creatorId", void 0);
tslib_1.__decorate([
    (0, typeorm_1.ManyToOne)(type => auth_base_1.User, {
        nullable: true
    }),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", auth_base_1.User)
], Process.prototype, "updater", void 0);
tslib_1.__decorate([
    (0, typeorm_1.RelationId)((process) => process.updater),
    tslib_1.__metadata("design:type", String)
], Process.prototype, "updaterId", void 0);
tslib_1.__decorate([
    (0, typeorm_1.DeleteDateColumn)(),
    (0, type_graphql_1.Field)({ nullable: true }),
    tslib_1.__metadata("design:type", Date)
], Process.prototype, "deletedAt", void 0);
Process = tslib_1.__decorate([
    (0, typeorm_1.Entity)(),
    (0, typeorm_1.Index)('ix_process_0', (process) => [process.domain, process.name, process.creator], {
        unique: true,
        where: '"deleted_at" IS NULL'
    }),
    (0, typeorm_1.Index)('ix_process_1', (process) => [process.domain, process.group, process.name]),
    (0, type_graphql_1.ObjectType)({ description: 'Entity for Integration Process' })
], Process);
exports.Process = Process;
//# sourceMappingURL=process.js.map