from flask_cors import CORS
from flask import Flask
from flask_restplus import Api
from threading import Thread
from scripts.common.logsetup import logger
from scripts.common.config import SERVICE_HOST, SERVICE_PORT
# from scripts.blueprints.invoice_configurations import invoices_blueprint

from scripts.blueprints.bot_configurations import klbot_blueprint, init_thread
from models.model import *

app = Flask(__name__)
api = Api(app, title=app_constants.SwaggerClass.title)
api.add_namespace(klbot_namespace)
app.register_blueprint(klbot_blueprint)
# api.add_namespace(invoice_namespace)
# app.register_blueprint(invoices_blueprint)

# app.register_blueprint(alarms_blueprint)


CORS(app, orgins="*", resources={r"/*": {"origins": "*"}}, allow_headers=[
    "Content-Type", "Authorization", "Access-Control-Allow-Credentials"],
     supports_credentials=True, intercept_exceptions=False)


for rule in app.url_map.iter_rules():
    logger.debug(rule)

# minio_obj = MinioClient('minioadmin', 'minioadmin', 'videobucket', '/home/svc-ilens/minio_files', '192.168.3.220:29000')
t = Thread(target=init_thread)
t.start()

app.run(host=SERVICE_HOST, port=2526, debug=False, threaded=True, use_reloader=False)
