import os

from flask import request, jsonify, make_response

from modules import logger
from modules.app import app
from modules.app.controllers.auth import auth_required
from modules.database.crud.crud_activity import add_activity
from modules.database.crud.crud_comment import add_comment, update_comment, delete_comment
from modules.database.models.ot_activity_t import Activity
from modules.database.models.ot_comment_t import Comment

ROOT_PATH = os.environ.get('ROOT_PATH')
LOG = logger.get_root_logger(__name__,
                             filename=os.path.join(ROOT_PATH, 'output.log'))

OBJECT_TYPES = ['CARD', 'ATTACHMENT']


@app.route('/<object_type>/<object_id>/comment', methods=['POST'])
@auth_required
def create_comment(user_id, object_type, object_id):
    object_type = object_type.upper()
    if object_type not in OBJECT_TYPES:
        status_code = 404
        data = {
            'status': 'failed',
            'message': 'Adding new comment failed, unsupported object type',
            'resource_id': object_id
        }
        return make_response(jsonify(data), status_code)
      }
    }
  }
}
'''.strip()
"""
:ROOT_PATH : Set root path
:PUBLIC_PATH : Always for joining react public index.html to ROOT_PATH
"""
ROOT_PATH = os.path.dirname(os.path.realpath(__file__))
os.environ.update({'ROOT_PATH': ROOT_PATH})
PUBLIC_PATH = os.path.join(ROOT_PATH, 'modules', 'client', 'public')
''' Set the view for Graphiql '''
view_func = GraphQLView.as_view('graphql', schema=schema, graphiql=True)
""" logger object to output info and debug information """
LOG = logger.get_root_logger(os.environ.get('ROOT_LOGGER', 'root'),
                             filename=os.path.join(ROOT_PATH, 'output.log'))

PORT = os.environ.get('PORT')

app.add_url_rule('/graphql', view_func=view_func)
""" Sets routes for Flask """


@app.errorhandler(404)
def not_found(error):
    """ error handler """
    LOG.error(error)
    return make_response(jsonify({'error': 'Not Found'}), 404)


@app.route('/')