"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.AppEndpointEntity = void 0;
const typeorm_1 = require("typeorm");
const cluster_entity_1 = require("../../infrastructure/clusters/entities/cluster.entity");
const cluster_dns_zone_entity_1 = require("./cluster-dns-zone.entity");
const wildcard_certificate_entity_1 = require("./wildcard-certificate.entity");
const san_certificate_entity_1 = require("./san-certificate.entity");
const application_entity_1 = require("../../applications/entities/application.entity");
const dns_provider_interface_1 = require("../../providers/interfaces/dns-provider.interface");
const certificate_provider_interface_1 = require("../../providers/interfaces/certificate-provider.interface");
const certificate_provider_enum_1 = require("../../providers/enums/certificate-provider.enum");
const reconciliation_status_enum_1 = require("../../infrastructure/shared/enums/reconciliation-status.enum");
const endpoint_type_enum_1 = require("../enums/endpoint-type.enum");
const cert_challenge_enum_1 = require("../enums/cert-challenge.enum");
const hostname_mode_enum_1 = require("../enums/hostname-mode.enum");
let AppEndpointEntity = class AppEndpointEntity {
};
exports.AppEndpointEntity = AppEndpointEntity;
__decorate([
    (0, typeorm_1.PrimaryGeneratedColumn)('uuid'),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "id", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid' }),
    __metadata("design:type", String)
], AppEndpointEntity.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)
], AppEndpointEntity.prototype, "cluster", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "clusterDnsZoneId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => cluster_dns_zone_entity_1.ClusterDnsZoneEntity, (zone) => zone.endpoints, {
        nullable: true,
    }),
    (0, typeorm_1.JoinColumn)({ name: 'clusterDnsZoneId' }),
    __metadata("design:type", cluster_dns_zone_entity_1.ClusterDnsZoneEntity)
], AppEndpointEntity.prototype, "clusterDnsZone", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "applicationId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => application_entity_1.ApplicationEntity, { nullable: true, onDelete: 'SET NULL' }),
    (0, typeorm_1.JoinColumn)({ name: 'applicationId' }),
    __metadata("design:type", application_entity_1.ApplicationEntity)
], AppEndpointEntity.prototype, "application", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: endpoint_type_enum_1.EndpointType,
        default: endpoint_type_enum_1.EndpointType.PUBLIC,
    }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "endpointType", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: cert_challenge_enum_1.CertChallenge,
        default: cert_challenge_enum_1.CertChallenge.HTTP_01,
    }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "certChallenge", void 0);
__decorate([
    (0, typeorm_1.Column)({
        type: 'enum',
        enum: hostname_mode_enum_1.HostnameMode,
        default: hostname_mode_enum_1.HostnameMode.IP,
    }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "hostnameMode", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar' }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "fqdn", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar' }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "serviceName", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar' }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "k8sServiceName", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar' }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "k8sNamespace", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'int' }),
    __metadata("design:type", Number)
], AppEndpointEntity.prototype, "k8sServicePort", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'enum', enum: dns_provider_interface_1.DnsRecordType, default: dns_provider_interface_1.DnsRecordType.A }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "dnsRecordType", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "dnsRecordValue", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "dnsRecordId", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'enum', enum: certificate_provider_enum_1.CertificateProvider, nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "certificateProvider", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'boolean', default: true }),
    __metadata("design:type", Boolean)
], AppEndpointEntity.prototype, "certificateRequired", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'enum', enum: certificate_provider_interface_1.CertificateStatus, nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "certificateStatus", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "certificateMessage", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], AppEndpointEntity.prototype, "certificateExpiresAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "wildcardCertificateId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => wildcard_certificate_entity_1.WildcardCertificateEntity, {
        nullable: true,
        onDelete: 'SET NULL',
    }),
    (0, typeorm_1.JoinColumn)({ name: 'wildcardCertificateId' }),
    __metadata("design:type", wildcard_certificate_entity_1.WildcardCertificateEntity)
], AppEndpointEntity.prototype, "wildcardCertificate", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "tlsSecretName", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'uuid', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "sanCertificateId", void 0);
__decorate([
    (0, typeorm_1.ManyToOne)(() => san_certificate_entity_1.SanCertificateEntity, {
        nullable: true,
        onDelete: 'SET NULL',
    }),
    (0, typeorm_1.JoinColumn)({ name: 'sanCertificateId' }),
    __metadata("design:type", san_certificate_entity_1.SanCertificateEntity)
], AppEndpointEntity.prototype, "sanCertificate", 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)
], AppEndpointEntity.prototype, "reconciliationStatus", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], AppEndpointEntity.prototype, "lastReconciliationAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'timestamptz', nullable: true }),
    __metadata("design:type", Date)
], AppEndpointEntity.prototype, "lastSyncedAt", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'varchar', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "syncedDomain", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'text', nullable: true }),
    __metadata("design:type", String)
], AppEndpointEntity.prototype, "errorMessage", void 0);
__decorate([
    (0, typeorm_1.Column)({ type: 'jsonb', nullable: true }),
    __metadata("design:type", Object)
], AppEndpointEntity.prototype, "metadata", void 0);
__decorate([
    (0, typeorm_1.CreateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], AppEndpointEntity.prototype, "createdAt", void 0);
__decorate([
    (0, typeorm_1.UpdateDateColumn)({ type: 'timestamptz' }),
    __metadata("design:type", Date)
], AppEndpointEntity.prototype, "updatedAt", void 0);
exports.AppEndpointEntity = AppEndpointEntity = __decorate([
    (0, typeorm_1.Entity)('app_endpoints'),
    (0, typeorm_1.Index)(['fqdn'], { unique: true })
], AppEndpointEntity);
