package com.danding.yang800.Presenter;

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

import com.danding.yang800.Entity.AddressInfo;
import com.danding.yang800.General.HttpCallBack;
import com.danding.yang800.OrderPayActivity;
import com.danding.yang800.PayResultActivity;
import com.danding.yang800.Util.LogUtil;
import com.danding.yang800.Util.StringUtil;
import com.danding.yang800.Util.ToastUtil;
import com.danding.yang800.Util.VolleyUtil;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;


public class PayResultActivityPresenter {
    private PayResultActivity context;
    SharedPreferences sp;

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


    public void submit(String storeSkuSn, String provinceName, String cityName, String districtName, String address
            , String userName, String mobile) {
        if (provinceName.equals("") || cityName.equals("") || districtName.equals("")) {
            ToastUtil.show(context, "省市区不能为空！");
            return;
        }
        if (address.equals("")) {
            ToastUtil.show(context, "详细地址不能为空！");
            return;
        }
        if (userName.equals("")) {
            ToastUtil.show(context, "收件人不能为空！");
            return;
        }

        HashMap<String, String> map = new HashMap<>();
        map.put("storeSkuSn", storeSkuSn);
        map.put("quantity", "1");
        map.put("provinceName", provinceName);
        map.put("cityName", cityName);
        map.put("districtName", districtName);
        map.put("address", address);
        map.put("userName", userName);
        map.put("mobile", mobile);
        map.put("payWay", "ALIPAY");
        new VolleyUtil(context).request(context, "order.giftBag.submit", true, map, new HttpCallBack() {
            @Override
            public void onSuccess(JSONObject json) {
                try {
                    String result = StringUtil.toString(json.getString("result"));
                    context.aliPay(result);
                } catch (Exception e) {

                }

            }

            @Override
            public void onerrSuccess() {

            }

            @Override
            public void onCatch() {

            }

            @Override
            public void onFail() {

            }
        });
    }


}
