'use strict';
const ForecastIO = require('forecast-io');
const forecast = new ForecastIO('TU_PROPIA_CLAVE_AQUI');
const LAT = '38.599932';
const LON = '-0.046696';
const LAT_BSAS = '-34.605664';
const LON_BSAS = '-58.498754';

/*
var request = require('request');

var APIKEY = "a1eae5b3ea234b0ea5dcbcccaa72195c";
var FORECAST_IO_URL = "https://api.forecast.io/forecast/";
var POSITION = "-34.605664,-58.498754";
*/

//https://api.forecast.io/forecast/a1eae5b3ea234b0ea5dcbcccaa72195c/-34.605664,-58.498754
// GET forecasts/posicion

exports.posicion = function(req, res) {
	res.render('forecasts/posicion', {posicion: "32.32, 58.8"});
};


// GET /forecasts/pronostico

exports.pronostico = function(req, res) {

	console.log("Entrando en exports.pronostico");

forecast
    .latitude(LAT_BSAS)            //\\ required: latitude, string.
    .longitude(LON_BSAS)          //\\ required: longitude, string.
    //.time('2016-01-28')             \\ optional: date, string 'YYYY-MM-DD'.
    .units('ca')                    //\\ optional: units, string, refer to API documentation.
    .language('es')                 //\\ optional: language, string, refer to API documentation.
    .exclude('minutely, hourly, daily, alerts, flags')     // \\ optional: exclude, string, refer to API documentation.
    //.extendHourly(true)             \\ optional: extend, boolean, refer to API documentation.
    .get()                          //\\ execute your get request.
    .then(respon => {                  //\\ handle your success response.
    	res.render('forecasts/pronostico', JSON.parse(respon));
        console.log(respon);
    })
    .catch(err => {                 //\\ handle your error response.
        console.log("Falló solicitud de pronóstico");
        console.log(err);
    })	
};



