package com.wasu.cs.mvp.presenter;

import com.wasu.cs.model.ChildrenBrandAreaModel;
import com.wasu.cs.mvp.IView.IBrandAreaView;
import com.wasu.cs.utils.JsonUtil;
import com.wasu.module.datafetch.DataFetchListener;
import com.wasu.module.datafetch.DataFetchModule;
import com.wasu.module.log.WLog;

import org.json.JSONObject;

/**
 * Created by chenming on 2016/11/28.
 *
 * @Description: 少儿品牌专区页面presenter
 * @email chenming@wasu.com
 */

public class ChildrenBrandAreaPresenter extends BasePresenter<IBrandAreaView> {

	ChildrenBrandAreaModel model;

	public void getBrandAreaData(String url) {
		DataFetchModule.getInstance().fetchJsonGet(url, new DataFetchListener.JsonListener() {
			@Override
			public void onJsonGet(int i, String s, JSONObject jsonObject) {
				if (jsonObject != null && model == null) {
					model = JsonUtil.fromJson(jsonObject.toString(), ChildrenBrandAreaModel.class);
					ChildrenBrandAreaPresenter.this.getMvpView().onGetDataSuccess(model);
				}else if(jsonObject ==null ){
					ChildrenBrandAreaPresenter.this.getMvpView().onGetDataFailed(
							new Throwable("ChildrenBrandArea data fetch failed"));

				}

			}
		});
	}
}
