import extend from "./extend";
const urlkey = 'url_key';
/**
 * 地址类
 */
class Url {
    /**
     * 认证地址
     */
    get auth() {
        let url = this.get();
        return url.auth;
    }

    /**
     * 接口地址
     */
    get api() {
        let url = this.get();
        return url.api;
    }

    /**
     * 设置地址
     * @param {object} url url对象
     * @param {string} url.auth 认证地址
     * @param {string} url.api 接口地址
     */
    set(url) {
        if (extend.isObject(url)) {
            extend.addStorage(urlkey, url);
        }
    }

    /**
     * 获取地址
     * @returns {{auth: string, api: string}}
     */
    get() {
        let url = extend.readStorage(urlkey);
        if (extend.isNull(url)) {
            url = {};
        }
        if (extend.isEmptyString(url.authUrl)) {
            url.auth = 'http://219.151.179.47:8087/'
        }
        if (extend.isEmptyString(url.authUrl)) {
            url.api = 'http://219.151.179.47:8081/'
        }
        return url;
    }
}

/**
 * 地址类
 */
export default new Url();