import { BaseDataDefinition } from "./BaseDataDefinition";
import { XDataType } from "../XDataType";
import { ValidationIssue } from "../../IDesignValidationProvider";
export class NumberDataDefinition extends BaseDataDefinition {
    constructor() {
        super(...arguments);
        this.type = XDataType.NUMBER;
        this.allowDecimals = true;
    }
    getStorageData() {
        let data = super.getStorageData();
        Reflect.set(data, "lowerBounds", this.lowerBounds);
        Reflect.set(data, "upperBounds", this.upperBounds);
        Reflect.set(data, "allowDecimals", this.allowDecimals);
        return data;
    }
    setStorageData(data) {
        super.setStorageData(data);
        this.lowerBounds = Reflect.get(data, "lowerBounds");
        this.upperBounds = Reflect.get(data, "upperBounds");
        this.allowDecimals = Reflect.get(data, "allowDecimals");
    }
    verifyValueType(value) {
        if (value === undefined)
            return new ValidationIssue("Undefined Value");
        if (this.list) {
            // check is array
            if (!Array.isArray(value))
                return new ValidationIssue(value + " is not a number array");
            // check each value is of right type
            for (let n of value) {
                if (typeof n !== "number" || isNaN(n))
                    return new ValidationIssue(value + " has array members that are not numbers");
            }
        }
        else {
            if (Array.isArray(value))
                return new ValidationIssue(value + " is a number array");
            if (typeof value !== "number" || isNaN(value))
                return new ValidationIssue(value + " is not a number");
        }
        return undefined;
    }
    convert(value) {
        if (value === undefined)
            return undefined;
        if (this.list) {
            if (Array.isArray(value)) {
                let output = [];
                for (let n of value) {
                    output.push(+n);
                }
                return output;
            }
            return value;
        }
        else {
            if (Array.isArray(value)) {
                return +value[0];
            }
            return +value;
        }
    }
}
//# sourceMappingURL=NumberDataDefinition.js.map