"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.AppRevisionEntity = void 0;
const typeorm_1 = require("typeorm");
const uuid_1 = require("uuid");
const application_entity_1 = require("./application.entity");
const application_status_enum_1 = require("../enums/application-status.enum");
const app_event_type_enum_1 = require("../enums/app-event-type.enum");
let AppRevisionEntity = class AppRevisionEntity {
    generateId() {
        if (!this.id) {
            this.id = (0, uuid_1.v4)();
        }
    }
};
exports.AppRevisionEntity = AppRevisionEntity;
__decorate([
    (0, typeorm_1.PrimaryColumn)('uuid'),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.BeforeInsert)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], AppRevisionEntity.prototype, "generateId", null);
__decorate([
    (0, typeorm_1.Column)('uuid'),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "applicationId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => application_entity_1.ApplicationEntity, (app) => app.revisions, {
        onDelete: 'CASCADE',
    }),
    (0, typeorm_1.JoinColumn)({ name: 'applicationId' }),
    __metadata("design:type", application_entity_1.ApplicationEntity)
], AppRevisionEntity.prototype, "application", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: app_event_type_enum_1.AppEventType,
        default: app_event_type_enum_1.AppEventType.DEPLOY,
    }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "eventType", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', nullable: true }),
    __metadata("design:type", Object)
], AppRevisionEntity.prototype, "actor", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], AppRevisionEntity.prototype, "changeMetadata", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'int', nullable: true }),
    __metadata("design:type", Number)
], AppRevisionEntity.prototype, "revisionNumber", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255, nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "imageRef", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255, nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "commitSha", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255, nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "chartVersion", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], AppRevisionEntity.prototype, "sourceConfigSnapshot", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '[]' }),
    __metadata("design:type", Array)
], AppRevisionEntity.prototype, "envSnapshot", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], AppRevisionEntity.prototype, "resourcesSnapshot", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'int', nullable: true }),
    __metadata("design:type", Number)
], AppRevisionEntity.prototype, "replicas", 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)
], AppRevisionEntity.prototype, "status", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "errorMessage", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "deployedBy", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "operationId", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "buildId", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], AppRevisionEntity.prototype, "k8sResourceHashes", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppRevisionEntity.prototype, "rollbackReason", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], AppRevisionEntity.prototype, "createdAt", void 0);
exports.AppRevisionEntity = AppRevisionEntity = __decorate([
    (0, typeorm_1.Entity)('app_revisions')
], AppRevisionEntity);
