import * as i0 from '@angular/core';
import { Injectable } from '@angular/core';

class DatapointParserService {
    constructor() {
        this.attributeToParse = [
            'target',
            'yellowRangeMin',
            'yellowRangeMax',
            'redRangeMin',
            'redRangeMax',
            'min',
            'max'
        ];
    }
    parseDatapoints(datapoints) {
        return datapoints.map(dp => this.parseDatapoint(dp));
    }
    parseDatapoint(datapoint) {
        if (!datapoint.c8y_Kpi) {
            return datapoint;
        }
        const kpi = datapoint.c8y_Kpi;
        for (const key of this.attributeToParse) {
            if (typeof kpi[key] === 'string') {
                const num = Number.parseFloat(kpi[key]);
                if (!Number.isNaN(num)) {
                    kpi[key] = num;
                }
                else {
                    delete kpi[key];
                }
            }
        }
        return datapoint;
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointParserService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointParserService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: DatapointParserService, decorators: [{
            type: Injectable,
            args: [{ providedIn: 'root' }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { DatapointParserService };
//# sourceMappingURL=c8y-ngx-components-datapoint-library-services.mjs.map
