var Server = require('../net/Server.js').Server;
var JsonRpcRequestProcessor = require('./JsonRpcRequestProcessor.js').JsonRpcRequestProcessor;
var HealthCheckMethod = require('./HealthCheckMethod.js').HealthCheckMethod;

var Assertions = require('../common/Assertions.js');

var JsonRpcServer  = exports.JsonRpcServer = function () {
    this._methods = {};

    Server.call(this, JsonRpcRequestProcessor);
    this.addMethod('_healthcheck', HealthCheckMethod);
};

JsonRpcServer.prototype = Object.create(Server.prototype);

JsonRpcServer.prototype.addMethod = function (key, method) {
    if (!this._methods.hasOwnProperty(key)) {
        this._methods[key] = method;
        return true;
    }

    return false;
};

JsonRpcServer.prototype.getMethod = function (key) {
    if (this._methods.hasOwnProperty(key)) {
        return this._methods[key];
    }

    return false;
};

JsonRpcServer.prototype.removeMethod = function (key) {
    if (this._methods.hasOwnProperty(key)) {
        delete this._methods[key];
        return true;
    }

    return false;
};

JsonRpcServer.Exceptions = {};
JsonRpcServer.Exceptions.WRONG_CLASS = "Method has to be an instanceof JsonRpcMethod";
