/**
 * Created by liangwensen on 3/14/16.
 */

import declare from 'zero-oop/declare';
import numberUtils from 'zero-lang/number';
import checkType from 'zero-lang/type';
import objectUtils from 'zero-lang/object';

let Store = declare({
    constructor(options) {
        objectUtils.extend(this, options);
    },

    storage: {},
    get(name, defaultValue) {
        let value = this.storage[name];
        return checkType.isUndefined(value) ? defaultValue : value;
    },

    set(name, value) {
        this.storage[name] = value;
    },

    del(name) {
        delete this.storage[name];
    },

    clear() {
        this.storage = {};
    },

    getInt(name, defaultValue) {
        let value = this.get(name);
        if (value === null) {
            return defaultValue;
        }

        return numberUtils.toInt(value);
    },

    getBoolean(name, defaultValue) {
        let value = this.get(name);
        if (value === null) {
            return defaultValue;
        }

        return value === 'true';
    },
});

export default Store;
