'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    _ = require('lodash'),
    request = require('request');

exports.search = function(req, res) {
    console.log('requests are coming in on create');
    console.log(req.body);


    var getGeoData = function(callback) {
        request.post({
            url: 'http://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer/Geoenrichment/enrich',
            json:true,
            form: {
                f: 'json',
                token: process.env.ESRI_TEMP_TOKEN,
                studyAreas: '[{"geometry":{"x":-117.1956,"y":34.0572}}]'
            }
        }, function(error, response, body){
            console.log(body.results[0].value.FeatureSet[0]);
            callback(body.results[0].value.FeatureSet[0].features[0]);
        });
    };

    getGeoData(function(geoResponse) {
        return res.json(geoResponse);
    })

};

/**
 * Create a Location
 */
exports.create = function(req, res) {

};

/**
 * Show the current Location
 */
exports.read = function(req, res) {

};

/**
 * Update a Location
 */
exports.update = function(req, res) {

};

/**
 * Delete an Location
 */
exports.delete = function(req, res) {

};

/**
 * List of Locations
 */
exports.list = function(req, res) {
    console.log(req);
};

@@ -597,44 +597,63 @@
 '%5B%7B%22
-geometry%22:%7B%22x%22:-117.1956,%22y%22:34.0572
+address%22:%7B%22text%22:%22601 E. Anapamu Street, Santa Barbara%22
 %7D%7D%5D'

change lat/log to address in getGeoData