package com.bbitcn.silk.utils.global;

import com.bbitcn.silk.utils.MMKVUtil;

/**
 * @Description MMKV
 * @Author DuanKaiji
 * @CreateTime 2024年03月27日 13:48
 */
public class Global {
    /**
     * Token
     */
    public static final String TOKEN = "TOKEN";
    /**
     * 公司ID
     */
    public static final String COMPANY_ID = "COMPANY_ID";
    public static final String REG_NAME = "REG_NAME";
    public static final String REG_TEL = "REG_TEL";
    public static final String TOKEN_TIME = "TOKEN_TIME";
    /**
     * 所属部门ID
     */
    public static final String DEP_SYS_ID = "DEP_SYS_ID";

    public static String getDepSysId() {
        return MMKVUtil.get(DEP_SYS_ID, "——");
    }

    public static boolean isTokenAvailable() {
        //10分钟后都没过期
        return System.currentTimeMillis() < MMKVUtil.get(TOKEN_TIME, 0L) - 10 * 60 * 1000;
    }

    public static String getRegName() {
        return MMKVUtil.get(REG_NAME, "——");
    }

    public static String getRegTel() {
        return MMKVUtil.get(REG_TEL, "——");
    }

    /**
     * 用户ID
     */
    public static final String USER_ID = "USER_ID";
    /**
     * 用户名
     */
    public static final String USER_NAME = "USER_NAME";
    /**
     * 用户账号
     */
    public static final String USER_ACCOUNT = "USER_ACCOUNT";
    /**
     * 密码
     */
    public static final String PASSWORD = "PASSWORD";
    /**
     * 设备码
     */
    public static final String DEVICE_ID = "DEVICE_ID";

    /**
     * 默认单位
     */
    public static final String UNIT = "UNIT";
    /**
     * 公司名称
     */
    public static final String COMPANY_NAME = "COMPANY_NAME";
    /**
     * 茧站名称
     */
    public static final String STATION_NAME = "STATION_NAME";

    public static String getStationName() {
        return MMKVUtil.get(STATION_NAME, "——");
    }

    public static String getDeviceId() {
        return MMKVUtil.get(DEVICE_ID, "——");
    }

    public static String getUnit() {
        return MMKVUtil.get(UNIT, SpinnerList.UNIT[0]);
    }

    public static String getCompanyId() {
        return MMKVUtil.get(COMPANY_ID, "未授权").toUpperCase();
    }

    public static String getUserName() {
        return MMKVUtil.get(USER_NAME, "——");
    }

    public static String getUserAccount() {
        return MMKVUtil.get(USER_ACCOUNT, null);
    }

    public static String getPassword() {
        return MMKVUtil.get(PASSWORD, null);
    }

    public static String getUserId() {
        return MMKVUtil.get(USER_ID, "——");
    }

    public static String getCompanyName() {
        return MMKVUtil.get(COMPANY_NAME, "——");
    }

    /**
     * 单位
     * 用于换算
     */
    public static int getUnitInt() {
        if (SpinnerList.UNIT[0].equals(getUnit())) {
            return 1;
        } else {
            return 2;
        }
    }
}
