'use strict';

/* Services */

angular.module('MarvelJSApp.services', [])
  .value('version', '0.1')
  .factory('marvelAPIservice',function($http, Setup, md5) {
		var marvelAPI = {};
		var marvelAPIGateWay = Setup.marvelapi;
		var marvelPublicKey = Setup.marvelPublicKey;
		var marvelPrivateKey = Setup.marvelPrivateKey;
		var marvelTS = 'OUR MARVEL PASS KEY';  // this can be any string
		var marvelHash = md5.createHash(marvelTS + marvelPrivateKey + marvelPublicKey);
		
		marvelAPI.getComics = function() {
			return {
				method : 'JSONP',
				params: {},
				paginationConfig: {
					request: {
						start: 'offset',
						pageSize: 'limit',
						page: '',
						sortField: 'sort',
						sortDirection: 'sort_dir',
						sortAscValue: 'asc',
						sortDescValue: 'desc'
					},
					response: {
						itemsLocation: 'data.results',
						totalItems: 'data.total'
					}
				},
				url : marvelAPIGateWay + 'comics?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			};
		}
		marvelAPI.getComicDetails = function(comicid) {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'comics/'+comicid+'?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getComicCreators = function(comicid) {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'comics/'+comicid+'/creators?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getComicEvents = function(comicid) {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'comics/'+comicid+'/events?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getCharacters = function() {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'characters?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getCreators = function() {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'creators?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getEvents = function() {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'events?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getSeries = function() {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'series?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}
		marvelAPI.getStories = function() {
			return $http({
				method : 'JSONP',
				url : marvelAPIGateWay + 'stories?apikey='
						+ marvelPublicKey + '&ts=' + marvelTS + '&hash='
						+ marvelHash + '&callback=JSON_CALLBACK'
			});
		}

		return marvelAPI;
	}
);

@@ -513,18 +513,24 @@
 %09return 
+$http(
 %7B%0A
-
 %09%09%09%09meth
@@ -547,348 +547,8 @@
 P',%0A
-%09%09%09%09params: %7B%7D,%0A%09%09%09%09paginationConfig: %7B%0A%09%09%09%09%09request: %7B%0A%09%09%09%09%09%09start: 'offset',%0A%09%09%09%09%09%09pageSize: 'limit',%0A%09%09%09%09%09%09page: '',%0A%09%09%09%09%09%09sortField: 'sort',%0A%09%09%09%09%09%09sortDirection: 'sort_dir',%0A%09%09%09%09%09%09sortAscValue: 'asc',%0A%09%09%09%09%09%09sortDescValue: 'desc'%0A%09%09%09%09%09%7D,%0A%09%09%09%09%09response: %7B%0A%09%09%09%09%09%09itemsLocation: 'data.results',%0A%09%09%09%09%09%09totalItems: 'data.total'%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D,%0A
 %09%09%09%09
@@ -691,20 +691,21 @@
 LLBACK'%0A
-
 %09%09%09%7D
+)
 ;%0A%09%09%7D%0A%09%09

fix getComics call broken to test adaptv