"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.ClusterNodeEntity = exports.NodeStatus = exports.NodeType = void 0;
const typeorm_1 = require("typeorm");
const uuid_1 = require("uuid");
const cluster_entity_1 = require("./cluster.entity");
var NodeType;
(function (NodeType) {
    NodeType["MASTER"] = "master";
    NodeType["WORKER"] = "worker";
})(NodeType || (exports.NodeType = NodeType = {}));
var NodeStatus;
(function (NodeStatus) {
    NodeStatus["CREATING"] = "creating";
    NodeStatus["JOINING"] = "joining";
    NodeStatus["READY"] = "ready";
    NodeStatus["ERROR"] = "error";
    NodeStatus["DELETING"] = "deleting";
})(NodeStatus || (exports.NodeStatus = NodeStatus = {}));
let ClusterNodeEntity = class ClusterNodeEntity {
    generateId() {
        if (!this.id) {
            this.id = (0, uuid_1.v4)();
        }
    }
};
exports.ClusterNodeEntity = ClusterNodeEntity;
__decorate([
    (0, typeorm_1.PrimaryColumn)('uuid'),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.BeforeInsert)(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", void 0)
], ClusterNodeEntity.prototype, "generateId", null);
__decorate([
    (0, typeorm_1.Column)(),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "clusterId", void 0);
__decorate([
    (0, typeorm_1.Column)(),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "serverName", void 0);
__decorate([
    (0, typeorm_1.Column)(),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "providerResourceId", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'enum', enum: NodeType }),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "nodeType", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "ipAddress", void 0);
__decorate([
    (0, typeorm_1.Column)({ nullable: true }),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "privateIp", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "subnetId", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: NodeStatus,
        default: NodeStatus.CREATING,
    }),
    __metadata("design:type", String)
], ClusterNodeEntity.prototype, "status", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'json', default: '{}' }),
    __metadata("design:type", Object)
], ClusterNodeEntity.prototype, "metadata", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], ClusterNodeEntity.prototype, "createdAt", void 0);
__decorate([
    (0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], ClusterNodeEntity.prototype, "updatedAt", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => cluster_entity_1.ClusterEntity, (cluster) => cluster.nodes, {
        onDelete: 'CASCADE',
    }),
    (0, typeorm_1.JoinColumn)({ name: 'clusterId' }),
    __metadata("design:type", cluster_entity_1.ClusterEntity)
], ClusterNodeEntity.prototype, "cluster", void 0);
exports.ClusterNodeEntity = ClusterNodeEntity = __decorate([
    (0, typeorm_1.Entity)('infrastructure_cluster_nodes')
], ClusterNodeEntity);
