import { BaseDataDefinition } from "./BaseDataDefinition";
import { XDataType } from "../XDataType";
import { ValidationIssue } from "../../IDesignValidationProvider";
export class BooleanDataDefinition extends BaseDataDefinition {
    constructor() {
        super(...arguments);
        this.type = XDataType.BOOLEAN;
    }
    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 boolean array");
            // check each value is of right type
            for (let n of value) {
                if (typeof n !== "boolean")
                    return new ValidationIssue(value + " has array members that are not boolean");
            }
        }
        else {
            if (Array.isArray(value))
                return new ValidationIssue(value + " is a number array");
            if (typeof value !== "boolean")
                return new ValidationIssue(value + " is not a boolean");
        }
        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(this.convertValueToBoolean(n));
                }
                return output;
            }
            return value;
        }
        else {
            return this.convertValueToBoolean(value);
        }
    }
    convertValueToBoolean(value) {
        if (value === undefined || value === null)
            return false;
        if (typeof value === "boolean")
            return value;
        // do some strings
        let stringVal = value.toString().toLowerCase();
        if (stringVal === "true")
            return true;
        if (stringVal === "false")
            return false;
        if (stringVal === "t")
            return true;
        if (stringVal === "f")
            return false;
        if (stringVal === "yes")
            return true;
        if (stringVal === "no")
            return false;
        return value;
    }
}
//# sourceMappingURL=BooleanDataDefinition.js.map