import { BaseDataDefinition } from "./BaseDataDefinition";
import { XDataType } from "../XDataType";
import { ValidationIssue } from "../../IDesignValidationProvider";
export class StringDataDefinition extends BaseDataDefinition {
    constructor() {
        super(...arguments);
        this.type = XDataType.STRING;
        this.validValues = [];
    }
    getStorageData() {
        let object = super.getStorageData();
        Reflect.set(object, 'validValues', this.validValues);
        Reflect.set(object, 'pattern', this.pattern);
        return object;
    }
    setStorageData(data) {
        super.setStorageData(data);
        this.validValues = Reflect.get(data, 'validValues');
        this.pattern = Reflect.get(data, 'pattern');
    }
    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 string array');
            // check each value is of right type
            for (let n of value) {
                if (typeof n !== 'string')
                    return new ValidationIssue(value + ' has array members that are not string');
            }
        }
        else {
            if (Array.isArray(value))
                return new ValidationIssue(value + ' is a string array');
            if (typeof value !== 'string')
                return new ValidationIssue(value + ' is not a string');
        }
        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.toString());
                }
                return output;
            }
            return value;
        }
        else {
            return value;
        }
    }
}
//# sourceMappingURL=StringDataDefinition.js.map