package com.danding.yang800.Presenter;

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

import com.danding.yang800.BuildConfig;
import com.danding.yang800.CheckTakePassActivity;
import com.danding.yang800.General.HttpCallBack;
import com.danding.yang800.Util.GeneralUtil;
import com.danding.yang800.Util.MD5Util;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.Util.VolleyUtil;

import org.json.JSONObject;

import java.util.HashMap;

public class CheckTakePassActivityPresenter {
    private CheckTakePassActivity context;
    SharedPreferences sp;

    public CheckTakePassActivityPresenter(CheckTakePassActivity context) {
        sp = context.getSharedPreferences("variable", Context.MODE_PRIVATE);
        this.context = context;
    }


    public void updateInfo(final String userId, final String withdrawCashPassword) {
        if (withdrawCashPassword.equals("")) {
            ToastUtil.show(context, "提现密码不能为空");
            return;
        }
        context.initDialog();
        final String withdrawCashPasswordEncode = GeneralUtil.encode(MD5Util.MD5(withdrawCashPassword) + "yang800_$_&_%_#_@");
        HashMap<String, String> map = new HashMap<>();
        map.put("userId", userId);
        map.put("withdrawCashPassword", withdrawCashPasswordEncode);
        new VolleyUtil(context).request(context,  "user.setting.verifyWithdrawCashPassword",true, map, new HttpCallBack() {
            @Override
            public void onSuccess(JSONObject json) {
                try {
                    context.success();
                    context.dismissDialog();
                } catch (Exception e) {
                    e.printStackTrace();
                    onCatch();
                }


            }


            @Override
            public void onerrSuccess() {
                context.dismissDialog();
            }

            @Override
            public void onCatch() {
                context.dismissDialog();
            }

            @Override
            public void onFail() {
                context.dismissDialog();
            }
        });

    }


}
