package com.danding.yang800.Presenter;

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

import com.danding.yang800.Adapter.GiftListAdapter;
import com.danding.yang800.Entity.GiftListInfo;
import com.danding.yang800.General.HttpCallBack;
import com.danding.yang800.GiftInfoActivity;
import com.danding.yang800.GiftListActivity;
import com.danding.yang800.Util.StringUtil;
import com.danding.yang800.Util.VolleyUtil;
import com.danding.yang800.Vo.GiftInfoVO;
import com.danding.yang800.Vo.GiftListVO;
import com.google.gson.Gson;

import org.json.JSONObject;

import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;

public class GiftInfoActivityPresenter {
    private GiftInfoActivity context;
    SharedPreferences sp;
    public GiftInfoActivityPresenter(GiftInfoActivity context) {
        sp = context.getSharedPreferences("variable", Context.MODE_PRIVATE);
        this.context = context;
    }
    public void getInfo(String storeSkuSn) {
        HashMap<String, String> map = new HashMap<>();
        map.put("storeSkuSn",storeSkuSn);
        new VolleyUtil(context).request(context,  "goods.giftBag.info", true,map, new HttpCallBack() {
            @Override
            public void onSuccess(JSONObject json) {
                try {
                    Gson gson = new Gson();
                    GiftInfoVO bean = gson.fromJson(json.toString(), GiftInfoVO.class);
                    GiftInfoVO.ResultBean  result = bean.getResult();
                    String  skuName=result.getSkuName();
                    String  imageUrl=result.getImageUrl();
                    String  content=result.getContent();
                    double marketPrice=result.getMarketPrice();
                    String  priceStr= new DecimalFormat("0.00").format(marketPrice);
                    String priceArray[] = StringUtil.splitDouble(priceStr);
                    String priceInt = "";
                    String price = "";
                    if (priceArray.length == 2) {
                        priceInt = priceArray[0] + ".";
                        price = priceArray[1];
                    }
                    context.initData(skuName,imageUrl,content,priceInt,price);
                }catch (Exception e){

                }

            }

            @Override
            public void onerrSuccess() {

            }

            @Override
            public void onCatch() {

            }

            @Override
            public void onFail() {

            }
        });
    }


}
