// src/domain/normalize/chargingConfig.js

/**
 * Normaliza eventos de config (quando o carregador manda config)
 */
function normalizeChargingConfig(data = {}) {
    const chargerId = data.charger_id || data.chargerId || data.id;
    const cfg = data.config || data.raw?.config || data;

    return {
        charger_id: chargerId,
        mqtt_topic: data.mqtt_topic || data.mqttTopic,
        config: {
            max_charging_current:
                cfg.max_charging_current ??
                cfg.maxChargingCurrent ??
                cfg.max_current ??
                cfg.maxCurrent ??
                undefined,

            require_auth: cfg.require_auth ?? cfg.requireAuth ?? undefined,
            rcm_enabled: cfg.rcm_enabled ?? cfg.rcmEnabled ?? undefined,
            temperature_limit:
                cfg.temperature_limit ??
                cfg.temperatureThreshold ??
                cfg.temp_limit ??
                undefined,
        },
        raw: data.raw || data,
        updated_at: new Date().toISOString(),
    };
}

module.exports = { normalizeChargingConfig };
