package com.wasu.cs.protocol;

import org.json.JSONObject;

import com.wasu.cs.model.SearchConfigModel;
import com.wasu.cs.protocol.SearchProtocol.ProtocolCallbackBase;
import com.wasu.module.datafetch.DataFetchListener.JsonListener;
import com.wasu.module.datafetch.DataFetchModule;

public class SearchConfigProtocol extends BaseProtocol {

	public void fetch(String url, final ProtocolCallbackBase callback) {
		DataFetchModule.getInstance().fetchJsonGet(url, new JsonListener() {

			@Override
			public void onJsonGet(int retcode, String extraMsg, JSONObject jsonObj) {
				if (null == jsonObj) {
					callback.onProtocolCallback(false, "protocol return data is null", null);
				} else {
					SearchConfigModel model = new SearchConfigModel();
					if (model.from(jsonObj)) {
						callback.onProtocolCallback(true, null, model);
					} else {
						callback.onProtocolCallback(false, "parser result data fail", null);
					}
				}
			}
		});
	}
}
