"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClusterMapperService = void 0;
const common_1 = require("@nestjs/common");
/**
 * Service responsible for mapping entities to DTOs
 */
let ClusterMapperService = class ClusterMapperService {
    /**
     * Map ClusterEntity to ClusterResponseDto
     */
    mapToDto(cluster) {
        // Extract VNet info from metadata if present
        const vnetConfig = cluster.metadata?.vnetConfig;
        const grafanaConfig = cluster.metadata?.grafana;
        const masterNode = cluster.nodes?.find((node) => node.nodeType === 'master');
        return {
            id: cluster.id,
            name: cluster.name,
            provider: cluster.provider,
            region: cluster.region,
            nodeSize: cluster.nodeSize,
            nodeCount: cluster.nodeCount,
            status: cluster.status,
            clusterType: cluster.clusterType,
            autoscalingEnabled: cluster.autoscalingEnabled,
            minNodes: cluster.minNodes,
            maxNodes: cluster.maxNodes,
            k3sVersion: cluster.k3sVersion,
            masterIpAddress: masterNode?.ipAddress,
            vnetId: vnetConfig?.vnetId,
            vnetName: vnetConfig?.vnetName,
            grafanaPrometheusUid: grafanaConfig?.prometheusUid,
            grafanaLokiUid: grafanaConfig?.lokiUid,
            nodes: cluster.nodes?.map((node) => ({
                id: node.id,
                serverName: node.serverName || `node-${node.id.substring(0, 8)}`,
                nodeType: node.nodeType,
                ipAddress: node.ipAddress,
                status: node.status,
                createdAt: node.createdAt,
            })) || [],
            createdAt: cluster.createdAt,
            updatedAt: cluster.updatedAt,
        };
    }
    /**
     * Map multiple entities to DTOs
     */
    mapToDtos(clusters) {
        return clusters.map((cluster) => this.mapToDto(cluster));
    }
};
exports.ClusterMapperService = ClusterMapperService;
exports.ClusterMapperService = ClusterMapperService = __decorate([
    (0, common_1.Injectable)()
], ClusterMapperService);
