import { ValidationIssue } from "../../../Common/IDesignValidationProvider";
export var ValueRuleCellType;
(function (ValueRuleCellType) {
    ValueRuleCellType["SINGLE"] = "single";
    ValueRuleCellType["MULTIPLE"] = "multiple";
    ValueRuleCellType["IGNORE"] = "any";
    ValueRuleCellType["MISSING"] = "missing";
})(ValueRuleCellType || (ValueRuleCellType = {}));
export class ValueRuleCell {
    constructor(columnId) {
        this.values = null;
        this._columnId = columnId;
    }
    getStorageData() {
        return this;
    }
    setStorageData(data) {
        this._columnId = Reflect.get(data, "_columnId");
        this.values = Reflect.get(data, "values");
    }
    validateCellData(datadef) {
        let issues = [];
        if (this.values === null || this.values === undefined) {
            issues.push(new ValidationIssue("Value required"));
        }
        else if (this.values !== ValueRuleCell.IGNORE_CELL_VALUE) {
            if (Array.isArray(this.values)) {
                for (let v of this.values) {
                    if (datadef.verifyValueType(v)) {
                        issues.push(new ValidationIssue("Invalid data type"));
                    }
                }
            }
            else if (datadef.verifyValueType(this.values)) {
                issues.push(new ValidationIssue("Invalid data type"));
            }
        }
        return issues;
    }
    get cellType() {
        if (this.values === ValueRuleCell.IGNORE_CELL_VALUE) {
            return ValueRuleCellType.IGNORE;
        }
        else if (Array.isArray(this.values) && typeof this.values !== "string") {
            return ValueRuleCellType.MULTIPLE;
        }
        else if (this.values === ValueRuleCell.MISSING_CELL_VALUE) {
            return ValueRuleCellType.MISSING;
        }
        return ValueRuleCellType.SINGLE;
    }
    set cellType(type) {
        if (type === ValueRuleCellType.IGNORE) {
            this.values = ValueRuleCell.IGNORE_CELL_VALUE;
        }
        else if (type === ValueRuleCellType.MISSING) {
            this.values = ValueRuleCell.MISSING_CELL_VALUE;
        }
        else if (type === ValueRuleCellType.MULTIPLE) {
            if (this.cellType === ValueRuleCellType.SINGLE) {
                this.values = [this.values];
            }
            else {
                this.values = [];
            }
        }
        else {
            if (this.cellType === ValueRuleCellType.MULTIPLE) {
                this.values = this.values[0];
            }
            else {
                this.values = undefined;
            }
        }
    }
}
ValueRuleCell.IGNORE_CELL_VALUE = "(( any ))";
ValueRuleCell.MISSING_CELL_VALUE = null;
//# sourceMappingURL=ValueRuleCell.js.map