"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.AppResourceEntity = void 0;
const typeorm_1 = require("typeorm");
const uuid_1 = require("uuid");
const application_entity_1 = require("./application.entity");
const application_resource_kind_enum_1 = require("../enums/application-resource-kind.enum");
const application_resource_status_enum_1 = require("../enums/application-resource-status.enum");
const reconciliation_status_enum_1 = require("../../infrastructure/shared/enums/reconciliation-status.enum");
let AppResourceEntity = class AppResourceEntity {
    generateId() {
        if (!this.id) {
            this.id = (0, uuid_1.v4)();
        }
    }
};
exports.AppResourceEntity = AppResourceEntity;
__decorate([
    (0, typeorm_1.PrimaryColumn)('uuid'),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.BeforeInsert)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], AppResourceEntity.prototype, "generateId", null);
__decorate([
    (0, typeorm_1.Column)('uuid'),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "applicationId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => application_entity_1.ApplicationEntity, (app) => app.appResources, {
        onDelete: 'CASCADE',
    }),
    (0, typeorm_1.JoinColumn)({ name: 'applicationId' }),
    __metadata("design:type", application_entity_1.ApplicationEntity)
], AppResourceEntity.prototype, "application", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_resource_kind_enum_1.ApplicationResourceKind,
    }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "kind", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255 }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "name", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 100 }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "namespace", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 255 }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "apiVersion", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: application_resource_status_enum_1.ApplicationResourceStatus,
        default: application_resource_status_enum_1.ApplicationResourceStatus.PENDING,
    }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "status", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 64, nullable: true }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "desiredHash", void 0);
__decorate([
    (0, typeorm_1.Column)({ length: 64, nullable: true }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "actualHash", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "desiredManifest", 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)
], AppResourceEntity.prototype, "reconciliationStatus", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], AppResourceEntity.prototype, "lastObservedAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppResourceEntity.prototype, "errorMessage", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', nullable: true }),
    __metadata("design:type", Object)
], AppResourceEntity.prototype, "metadata", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], AppResourceEntity.prototype, "createdAt", void 0);
__decorate([
    (0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], AppResourceEntity.prototype, "updatedAt", void 0);
exports.AppResourceEntity = AppResourceEntity = __decorate([
    (0, typeorm_1.Entity)('app_resources')
], AppResourceEntity);
