"use strict";
// -*- mode: typescript; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2020 The Board of Trustees of the Leland Stanford Junior University
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SlotBag = void 0;
const assert_1 = __importDefault(require("assert"));
const thingtalk_1 = require("thingtalk");
const utils_1 = require("./utils");
class SlotBag {
    constructor(schema) {
        this.schema = schema;
        this.store = new Map;
    }
    static merge(b1, b2) {
        const schema1 = b1.schema;
        const schema2 = b2.schema;
        if (schema1 !== null && schema2 !== null && !utils_1.isSameFunction(schema1, schema2))
            return null;
        const newbag = new SlotBag(schema1 || schema2);
        for (const [key, value] of b1.entries())
            newbag.set(key, value.clone());
        for (const [key, value] of b2.entries()) {
            if (newbag.has(key))
                return null;
            newbag.set(key, value.clone());
        }
        return newbag;
    }
    clone() {
        const newbag = new SlotBag(this.schema);
        for (const [key, value] of this.entries())
            newbag.set(key, value.clone());
        return newbag;
    }
    get size() {
        return this.store.size;
    }
    entries() {
        return this.store.entries();
    }
    get(key) {
        return this.store.get(key);
    }
    has(key) {
        return this.store.has(key);
    }
    keys() {
        return this.store.keys();
    }
    values() {
        return this.store.values();
    }
    [Symbol.iterator]() {
        return this.store[Symbol.iterator]();
    }
    set(key, value) {
        assert_1.default(value instanceof thingtalk_1.Ast.Value);
        this.store.set(key, value);
    }
    clear() {
        return this.store.clear();
    }
    delete(key) {
        return this.store.delete(key);
    }
}
exports.SlotBag = SlotBag;
//# sourceMappingURL=slot_bag.js.map