define(["dojo/store/util/QueryResults", "dojo/_base/declare", "dojo/_base/lang", "dojo/_base/xhr", "dojo/store/util/SimpleQueryEngine","dojo/store/api/Store"],
        function(QueryResults, declare, lang, xhr, SimpleQueryEngine,Store){
    var base=null;
    //  Declare the initial store
    return declare("chy.store.Json",base, {
        idProperty: "id",
        queryEngine: SimpleQueryEngine,
        startLength:0,
        target: "",
 
        constructor: function(options){
            lang.mixin(this, options || {});
        },
        query: function(query, options){
		var hasQuestionMark = this.target.indexOf("?") > -1;
		if(query && typeof query == "object"){
			query = xhr.objectToQuery(query);
			query = query ? (hasQuestionMark ? "&" : "?") + query: "";
		}
		var queryVal=query.split('=');
		if (queryVal.length>=2)queryVal=queryVal[1];
		queryVal=queryVal.replace(/\*/g,'');
		
		
		if (queryVal.length>=this.startLength||queryVal.length==0) 
		{
			
	        	var results = xhr("GET", {
				url: this.target + (query || ""),
				handleAs: "json"
			}).then(function(data){
					return [].concat(data.option);
				});
			return QueryResults(results);    
		 }
		 return new Store.QueryResults();
            
        },
        getIdentity: function(object){
		// summary:
		//		Returns an object's identity
		// object: Object
		//		The object to get the identity from
		// returns: Number
		return object[this.idProperty];
	},
        get:function(id){
        	console.log("Get called with id:" + id);
        	}
    });
});