#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Third-party modules
from flask import Blueprint
from flask_restx import Api
from util import exception
from Ice import ConnectionRefusedException

# Custom modules
from .blocks import api as blocks_api
from .bob import api as bob_api
from .devices import api as devices_api
from .dm import api as dm_api
from .rtc import api as rtc_api
from .teccam import api as teccam_api

api_blueprint = Blueprint('api', __name__)

api = Api(api_blueprint,
          title='My Title',
          version='1.0',
          description='SHARK-NIR REST APIs',
)

api.add_namespace(blocks_api)
api.add_namespace(bob_api)
api.add_namespace(devices_api)
api.add_namespace(dm_api)
api.add_namespace(rtc_api)
api.add_namespace(teccam_api)

@api.errorhandler(exception.TemplateException)
def handle_TemplateException(error):
    '''Return a custom message and 400 status code'''    
    return {'message': 'TemplateException'}, 200

@api.errorhandler(Exception)
def handle_IceConnectionRefusedException(ConnectionRefusedException):
    '''Return a custom message and 400 status code'''
    return {'message': 'ConnectionRefusedException'}, 200
