'use strict';

var NewslettersService = angular.module('newsletters.services', [
    'system'
])
    .factory('NewslettersService',  [
        '$http',
        '$q',
        'System',
        'NewslettersFactory',
        function ($http, $q, System, NewslettersFactory) {

            var URL = {

                CREATE: '/cms/api/newsletterlaktasi/Create',
                GET_FOR_EDIT: '/cms/api/newsletterlaktasi/Edit',
                SENDMESSAGE: '/cms/api/newsletterlaktasi/SendMessage',
            };

            var get = function (id) {
                var deferred = $q.defer();
                $http.get(URL.GET_FOR_EDIT, {
                    params: { id: id }
                }).success(function (data) {
                    var newsletter = data;
                    deferred.resolve(newsletter);
                });
                return deferred.promise;
            };

            var create = function (newsletter) {
                var deferred = $q.defer();
                $http.post(URL.CREATE, newsletter)
                    .success(function (data) {
                        deferred.resolve(data);
                    });

                return deferred.promise;
            };

            var sendMessage = function (newsletter) {
                var deferred = $q.defer();
                $http.post(URL.SENDMESSAGE, newsletter)
                    .success(function (data) {
                        deferred.resolve(data);
                    });

                return deferred.promise;
            };

            return {
                get: get,
                create: create,
                sendMessage: sendMessage,
            };
        }
    ]);
