package com.fxy.constant;

import android.content.Context;
import android.content.SharedPreferences;


/**
 * 用户缓存对象
 *
 * @date 2020-02-02
 */

public class SPCache {
    private static SPCache spCache;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;

    private SPCache(Context context) {
        sp = context.getSharedPreferences(BaseConfig.SPName, Context.MODE_PRIVATE);
        editor = sp.edit();
    }

    public static SPCache getInstance(Context context) {
        if (spCache == null) {
            spCache = new SPCache(context);
        }
        return spCache;
    }

    /**
     * 设置客户端类型
     */
    public void setClientCode(String clientCode) {
        editor.putString("clientCode", clientCode).commit();
    }

    /**
     * 用户ID
     */
    public void setUserId(String userId) {
        editor.putString("userId", userId).commit();
    }

    public String getUserId() {
        return sp.getString("userId", "");
    }

    /**
     * 用户仓库ID
     */
    public void setWareHouseId(String wareHouseId) {
        editor.putString("wareHouseId", wareHouseId).commit();
    }

    public String getWareHouseId() {
        return sp.getString("wareHouseId", "");
    }
    /**
     * 用户仓库名称
     */
    public void setWareHouseName(String wareHouseName) {
        editor.putString("wareHouseName", wareHouseName).commit();
    }

    public String getWareHouseName() {
        return sp.getString("wareHouseName", "");
    }


    /**
     * 性别
     */
    public String getGender() {
        return sp.getString("gender", "");
    }

    public void setGender(String gender) {
        editor.putString("gender", gender).commit();
    }

    /**
     * 头像
     */
    public String getAvatarUrl() {
        return sp.getString("avatarUrl", "");
    }

    public void setAvatarUrl(String avatar_url) {
        editor.putString("avatarUrl", avatar_url).commit();
    }

    /**
     * token
     */
    public void setToken(String token) {
        editor.putString("token", token).commit();
    }

    public String getToken() {
        return sp.getString("token", "");
    }
    public void clearCache() {
        editor.clear();
        editor.apply();
    }

    /**
     * 用户名称
     */
    public void setUserName(String userName) {
        editor.putString("userName", userName).commit();
    }

    public String getUserName() {
        return sp.getString("userName", "");
    }
    public void setAccountName(String accountName) {
        editor.putString("accountName", accountName).commit();
    }

    public String getAccountName() {
        return sp.getString("accountName", "");
    }
    /**
     * 用户手机
     */
    public void setUserPhone(String userPhone) {
        editor.putString("userPhone", userPhone).commit();
    }

    /**
     * 重量单位
     * @return
     */
    public String getWeightUnit() {
        return sp.getString("weight_unit", "");
    }
    public void setWeightUnit(String weight_unit){
        editor.putString("weight_unit", weight_unit).commit();
    }
    /**
     * 公司名称
     * @return
     */
    public String getCompanyName() {
        return sp.getString("company_name", "");
    }
    public void setCompanyName(String company_name){
        editor.putString("company_name", company_name).commit();
    }
    //保存本版描述信息
    public String getVersion() {
        return sp.getString("version_describe", "");
    }
    public void setVersion(String version_describe){
        editor.putString("version_describe", version_describe).commit();
    }


    /**
     * 蓝牙对象json  获取以后需要转换
     */
    public Object getBluesScalePin() {
        return sp.getString("bluesScalePin", "[{\"blue_ele_scale\":\"HC-06\",\"blue_ele_scale_pin\":\"1234\",\"reverse\":0,\"continuous\":1,\"is_record_log\":0,\"is_clear_weight\":0}]");
    }

    public void setBluesScalePin(String bluesScalePin) {
        editor.putString("bluesScalePin", bluesScalePin).commit();
    }

    public String getCurrentBluesScale() {
        return sp.getString("current_blues_scale", "");
    }
    public void setCurrentBluesScale(String current_blues_scale){
        editor.putString("current_blues_scale", current_blues_scale).commit();
    }

    //托盘入库托盘
    public String getPalletNo() {
        return sp.getString("put_in_pallet_no", "");
    }
    public void setPalletNo(String version_info){
        editor.putString("put_in_pallet_no", version_info).commit();
    }

    //保存理货信息
    public String getTallyInfo() {
        return sp.getString("tally_info", "");
    }
    public void setTallyInfo(String version_info){
        editor.putString("tally_info", version_info).commit();
    }

    public String getTallyList() {
        return sp.getString("tally_list", "");
    }
    public void setTallyList(String version_info){
        editor.putString("tally_list", version_info).commit();
    }

    //记录移位
    public String getMoveId() {
        return sp.getString("move_id", "");
    }
    public void setMoveId(String move_id){
        editor.putString("move_id", move_id).commit();
    }


    // 仓储资源 域名
    public String getResourceHost() {
        return sp.getString("resource_host", "https://ossfiles.365jq.com");
    }
    public void setResourceHost(String version_info){
        editor.putString("resource_host", version_info).commit();
    }

    // 仓储资源 类型
    public String getResourceType() {
        return sp.getString("resource_type", "aliyun");
    }
    public void setResourceType(String version_info){
        editor.putString("resource_type", version_info).commit();
    }

    // 仓储资源 类型
    public String getResourcePrefix() {
        return sp.getString("resource_prefix", "");
    }
    public void setResourcePrefix(String version_info){
        editor.putString("resource_prefix", version_info).commit();
    }

    public String getResourceRegion() {
        return sp.getString("resource_region", "");
    }
    public void setResourceRegion(String version_info){
        editor.putString("resource_region", version_info).commit();
    }

    public String getResourceBucket() {
        return sp.getString("resource_bucket", "");
    }
    public void setResourceBucket(String version_info){
        editor.putString("resource_bucket", version_info).commit();
    }

    //业务类型
    public int getBusinessType() {
        return sp.getInt("business_type", 0);
    }
    public void setBusinessType(int business_type){
        editor.putInt("business_type", business_type).commit();
    }




}
