import Item from "./item"
class Kitchen {
    private _list: Array<Item>
    constructor() {
        this._list = [];
    }
    use(id) {
        this._list = this._list.map(li => {
            if (li.id == id) li.num -= 1;
            return li;
        })
    }
    buy(id) {

        this._list = this._list.map(li => {
            if (li.id == id) li.num += 1;
            return li;
        })
    }
    getListByType(type: number) {
        return this._list.filter(li => li.type == type)
    }
    parse(list: any) {
        if (!list) return;
        this._list = list.map(li => { return new Item(li); })
    }
    get list() {
        return this._list;
    }
}
let kitchen = new Kitchen();
export default kitchen;
