text: 'use strict';
  
  angular.module('owsWalletApp.pluginApi').service('closeSession', function(lodash, pluginSessionService) {
  
  	var root = {};
  
    root.respond = function(message, callback) {
  	  // Request parameters.
      var sessionId = message.request.params.id;
      var opts = message.request.data.opts;
  
    	if (lodash.isUndefined(sessionId) || sessionId.length <= 0) {
  	    message.response = {
  	      statusCode: 400,
  	      statusText: 'REQUEST_NOT_VALID',
  	      data: {
  	      	message: 'The request must include a session id.'
  	      }
  	    };
  			return callback(message);
    	}
  
  		// Get the session.
  		var session = pluginSessionService.getSession(sessionId);
  
  		if (lodash.isUndefined(session)) {
  	    message.response = {
  	      statusCode: 404,
  	      statusText: 'SESSION_NOT_FOUND',
  	      data: {
  	      	message: 'Session not found.'
  	      }
  	    };
  			return callback(message);
  		}
  
  		session.close(opts);
  
  		// Closing the session does not provide a response.
  
  	};
  
    return root;
  });
  