var client = require('swagger-client');

var urlSwaggerJson = 'http://localhost:3000/swagger/';

var swagger = new client({
    url: urlSwaggerJson,
    success: function () {
    }
});

module.exports = [
    {
        method: 'GET',
        path: '/livros/',
        handler: function (request, reply) {
            swagger.livro.list({max: 10, offset: 0}, function (response) {
                reply(response.data).type('application/json')
            }, function (response) {
                reply(response.data).code(500).type('application/json')
            });
        }
    },
    {
        method: 'GET',
        path: '/livros/{livroId}',
        handler: function (request, reply) {
            swagger.livro.getById({livroId: request.params.livroId}, function (response) {
                reply(response.data).type('application/json')
            }, function (response) {
                reply(response.data).code(500).type('application/json')
            });
        }
    },
    {
        method: 'DELETE',
        path: '/livros/{id}',
        handler: function (request, reply) {
            swagger.livro.delete({livroId: request.params.id}, function (response) {
                reply(response.data).type('application/json')
            }, function (response) {
                reply(response.data).code(500).type('application/json')
            });
        }
    },
    {
        method: 'POST',
        path: '/livros/',
        handler: function (request, reply) {
            swagger.livro.create({livro: request.payload}, function (response) {
                reply(response.data).type('application/json')
            }, function (response) {
                reply(response.data).code(500).type('application/json')
            });
        }
    },
    {
        method: 'PUT',
        path: '/livros/{id}',
        handler: function (request, reply) {
            swagger.livro.update({livro: request.payload, livroId: request.params.id}, function (response) {
                reply(response.data).type('application/json')
            }, function (response) {
                reply(response.data).code(500).type('application/json')
            });
        }
    }
];