import DataType from "../../../core/parser/simple/DataType.js";
import Vector1 from "../../../core/geom/Vector1.js";
import ObservedBoolean from "../../../core/model/ObservedBoolean.js";
import ObservedString from "../../../core/model/ObservedString.js";

/**
 *
 * @param {DataType} type
 * @returns {Vector1|ObservedBoolean}
 */
function createValueByType(type) {

    let value;

    switch (type) {
        case DataType.Number:
            value = new Vector1(0);
            break;
        case DataType.Boolean:
            value = new ObservedBoolean(false);
            break;
        case DataType.String:
            value = new ObservedString("");
            break;
        default:
            throw new TypeError(`Unsupported data type '${type}'`);
    }

    return value;
}

export class BlackboardValue {
    /**
     *
     * @param {DataType} type
     */
    constructor(type) {
        /**
         *
         * @type {number}
         */
        this.referenceCount = 0;
        /**
         *
         * @type {DataType}
         */
        this.type = type;
        this.value = createValueByType(type);
    }
}
