package com.kfzs.duanduan.utils.dlg;

import android.text.TextUtils;

import com.sheep.jiuyan.samllsheep.utils.G;
import com.kfzs.duanduan.KFZSApp;
import com.sheep.jiuyan.samllsheep.R;
import com.kfzs.duanduan.datashare.DDProviderHelper;

/**
 * @ Created by Dlg
 * @ <p>TiTle:  CheckUtils</p>
 * @ <p>Description:</p>
 * @ date:  2017/12/7 10:45
 * @ QQ:    315096953
 */

public class CheckUtils {

    private static CheckUtils mCheckUtils;

    private CheckUtils() {

    }

    public static synchronized CheckUtils getInstance() {
        if (mCheckUtils == null) {
            mCheckUtils = new CheckUtils();
        }
        return mCheckUtils;
    }

    /**
     * 检查手机号是否符合条件
     *
     * @return
     */
    public boolean isPhoneSucc(String phone) {
        if (TextUtils.isEmpty(phone)) {
            G.showToast(R.string.tv_user_login_act_please_input_phone_error);
            return false;
        }
        if (phone.length() != KFZSApp.context.getResources()
                .getInteger(R.integer.size_phone_number)) {
            G.showToast(R.string.toast_warning_phone_number_size);
            return false;
        }
        return true;
    }


    /**
     * 验证登录数据是否可用
     *
     * @param user
     * @param pass
     * @return
     */
    public boolean isLoginParamsSuccs(String user, String pass) {
        if (TextUtils.isEmpty(user)) {
            G.showToast(R.string.tv_user_login_act_please_input_username);
            return false;
        }
        if (TextUtils.isEmpty(pass)) {
            G.showToast(R.string.tv_user_login_act_please_input_password);
            return false;
        }
        if (user.length() < KFZSApp.context.getResources().getInteger(R.integer.size_less_user_name)) {
            G.showToast(R.string.toast_warning_user_name_less);
            return false;
        }
        if (pass.length() < KFZSApp.context.getResources().getInteger(R.integer.size_less_password)) {
            G.showToast(R.string.toast_warning_password_less);
            return false;
        }
        return true;
    }

    /**
     * 当前是否是登录状态
     *
     * @return
     */
    public boolean isLogin() {
        return !TextUtils.isEmpty(DDProviderHelper.getInstance().getLastUserToken(KFZSApp.context));
    }

}
