{{#models}}
/** filename: com/{{&sdknameLower}}/{{&safeName}}.java **/
package com.{{&sdknameLower}};

import android.os.AsyncTask;

import java.util.Date;
import java.util.HashMap;
import java.net.HttpURLConnection;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class {{&safeName}} {

    /*
     Constructors.
     */
    public {{&safeName}}() {
    }

    public static {{&safeName}} parse(JSONObject object) throws JSONException {
        {{&safeName}} retVal = new {{&safeName}}();
        {{#fields}}
        if (object.has("{{name}}")) {
            retVal.set{{safeName}}(({{type}}) object.get("{{name}}"));
        }
        {{/fields}}
        return retVal;
    }

    /*
     Cache
     */
    private static CachePolicy cachePolicy = null;

    public static CachePolicy getCachePolicy() {
        return cachePolicy;
    }

    public static void setCachePolicy(CachePolicy cachePolicy) {
        {{&safeName}}.cachePolicy = cachePolicy;
    }

    /*
     Fields
     */
    {{#fields}}
    private {{type}} {{safeName}};

    public {{type}} get{{safeName}}() {
        return {{safeName}};
    }

    public void set{{safeName}}({{type}} val) {
        {{safeName}} = val;
    }

    {{/fields}}

    /*
     Methods.
     */
    {{#endpoints}}

    public static void {{&describes}}(
        {{#args}}
            final {{&.}},
        {{/args}}
        {{> Class.Callback.java}}
    ) {
        {{&describes}}({{#argNames}}{{&.}}, {{/argNames}}{{modelSafeName}}.cachePolicy, callback);
    }

    public static void {{&describes}}(
        {{#args}}
            final {{&.}},
        {{/args}}
            final CachePolicy cachePolicy,
        {{> Class.Callback.java}}
    ) {
        new AsyncTask<Void, Void, Void>() {
            protected Void doInBackground(Void... unused) {
                HttpURLConnection connection = null;
                JSONObject body = null;
                try {
                    String url = "{{&path}}";
                    {{#pathParams}}
                    url = url.replaceAll(":{{&.}}", {{&.}});
                    {{/pathParams}}
                    API api = {{&sdkname}}.getAPI(url, "{{method}}", cachePolicy);

                    {{> Class.DeclareResult.java}}
                    connection = result.getConnection();
                    body = result.getBody();

                    if (result.isSuccessful()) {
                        {{> Class.HandleResult.java}}
                    } else {
                        callback.onError(result.getError(), body, connection);
                    }
                } catch (Exception e) {
                    callback.onError(e, body, connection);
                }
                return null;
            }
        }.execute();
    }
    {{/endpoints}}
}
{{/models}}