"use strict";
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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplicationEntity = void 0;
const typeorm_1 = require("typeorm");
const uuid_1 = require("uuid");
const cluster_entity_1 = require("../../infrastructure/clusters/entities/cluster.entity");
const app_revision_entity_1 = require("./app-revision.entity");
const app_resource_entity_1 = require("./app-resource.entity");
const application_category_enum_1 = require("../enums/application-category.enum");
const application_kind_enum_1 = require("../enums/application-kind.enum");
const application_source_type_enum_1 = require("../enums/application-source-type.enum");
const application_status_enum_1 = require("../enums/application-status.enum");
const application_exposure_enum_1 = require("../enums/application-exposure.enum");
const reconciliation_status_enum_1 = require("../../infrastructure/shared/enums/reconciliation-status.enum");
let ApplicationEntity = class ApplicationEntity {
    generateId() {
        if (!this.id) {
            this.id = (0, uuid_1.v4)();
        }
    }
};
exports.ApplicationEntity = ApplicationEntity;
__decorate([
    (0, typeorm_1.PrimaryColumn)('uuid'),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.BeforeInsert)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ApplicationEntity.prototype, "generateId", null);
__decorate([
    (0, typeorm_1.Column)({ length: 255 }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "name", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255, unique: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "slug", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "description", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_category_enum_1.ApplicationCategory,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "category", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_kind_enum_1.ApplicationKind,
        default: application_kind_enum_1.ApplicationKind.APPLICATION,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "kind", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_source_type_enum_1.ApplicationSourceType,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "sourceType", void 0);
__decorate([
    (0, typeorm_1.Column)('uuid'),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "clusterId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => cluster_entity_1.ClusterEntity, { onDelete: 'CASCADE' }),
    (0, typeorm_1.JoinColumn)({ name: 'clusterId' }),
    __metadata("design:type", cluster_entity_1.ClusterEntity)
], ApplicationEntity.prototype, "cluster", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 100, default: 'default' }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "k8sNamespace", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_status_enum_1.ApplicationStatus,
        default: application_status_enum_1.ApplicationStatus.PENDING,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "status", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: reconciliation_status_enum_1.ReconciliationStatus,
        default: reconciliation_status_enum_1.ReconciliationStatus.PENDING,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "reconciliationStatus", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "lastReconciliationAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "reconciliationError", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "sourceConfig", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '[]' }),
    __metadata("design:type", Array)
], ApplicationEntity.prototype, "env", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "resources", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "scaling", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', nullable: true }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "healthProbe", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '[]' }),
    __metadata("design:type", Array)
], ApplicationEntity.prototype, "volumes", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'varchar',
        length: 20,
        default: 'Deployment',
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "workloadKind", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'int', default: 1 }),
    __metadata("design:type", Number)
], ApplicationEntity.prototype, "replicas", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'int', nullable: true }),
    __metadata("design:type", Number)
], ApplicationEntity.prototype, "port", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "currentRevisionId", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "imageRef", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "startCommand", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "userId", void 0);
__decorate([
    (0, typeorm_1.Column)({ default: false }),
    __metadata("design:type", Boolean)
], ApplicationEntity.prototype, "systemProtected", void 0);
__decorate([
    (0, typeorm_1.Column)({ default: false }),
    __metadata("design:type", Boolean)
], ApplicationEntity.prototype, "autoDeploy", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_exposure_enum_1.ApplicationExposure,
        default: application_exposure_enum_1.ApplicationExposure.PUBLIC,
    }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "exposure", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "labels", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "metadata", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'boolean', default: false }),
    __metadata("design:type", Boolean)
], ApplicationEntity.prototype, "preDeploySnapshotEnabled", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 32, default: 'best_effort' }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "preDeploySnapshotPolicy", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{"maxCopies":5,"days":7}' }),
    __metadata("design:type", Object)
], ApplicationEntity.prototype, "preDeployRetention", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "lastDeployedAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 50, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "buildPath", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "workflowRunId", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "workflowRunUrl", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "buildStartedAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 20, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "lastBuildStatus", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 20, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "lastBuildConclusion", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "webhookToken", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 100, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "frameworkConfirmed", void 0);
__decorate([
    (0, typeorm_1.Column)({ default: false }),
    __metadata("design:type", Boolean)
], ApplicationEntity.prototype, "isFluiManaged", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 16, default: 'shared' }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "persistenceScope", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', length: 253, nullable: true }),
    __metadata("design:type", String)
], ApplicationEntity.prototype, "dedicatedNodeName", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "createdAt", void 0);
__decorate([
    (0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "updatedAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], ApplicationEntity.prototype, "deletedAt", void 0);
__decorate([
    (0, typeorm_1.OneToMany)(() => app_revision_entity_1.AppRevisionEntity, (revision) => revision.application, {
        cascade: true,
    }),
    __metadata("design:type", Array)
], ApplicationEntity.prototype, "revisions", void 0);
__decorate([
    (0, typeorm_1.OneToMany)(() => app_resource_entity_1.AppResourceEntity, (resource) => resource.application, {
        cascade: true,
    }),
    __metadata("design:type", Array)
], ApplicationEntity.prototype, "appResources", void 0);
exports.ApplicationEntity = ApplicationEntity = __decorate([
    (0, typeorm_1.Entity)('applications')
], ApplicationEntity);
