package com.wasu.cs.protocol;

import org.json.JSONObject;

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

public class FilterConditionProtocol 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 from server is null", null);
				} else {
					FilterConditionModel model = new FilterConditionModel();
					if (model.from(jsonObj)) {
						callback.onProtocolCallback(true, null, model);
					} else {
						callback.onProtocolCallback(false, "parser result data fail", null);
					}
				}
			}
		});
	}
}
