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

# System modules
import json  # for users


# Third-party modules
from flask import Blueprint
from flask_restx import Api, reqparse
from flask_httpauth import HTTPBasicAuth

# Custom modules
from .server import web as server_web
# from .blocks import web as blocks_web
# from .control import web as control_web
# from .display import web as display_web
# from .environment import web as environment_web
# #from .home import web as home_web
# from .init import web as init_web
# from .other import web as other_web
# from .templates import web as templates_web
# from .testfulvio import web as testfulvio_web
# from .webcam import web as webcam_web

auth = HTTPBasicAuth()

users_file = 'users.json'

try:
    with open(users_file) as json_file:
        users = json.load(json_file)
except FileNotFoundError as e:
    print(f"{users_file} containing user:pass not found")
    exit(0)


@auth.verify_password
def verify(username, password):
    if not (username and password):
        return False
    return users.get(username) == password

############################
# WEB VIEW
############################

web_blueprint = Blueprint('web', __name__)

web = Api(web_blueprint,
          title='OARPAF Web view for observatory control',
          version='1.0',
          description='A description',
          decorators=[auth.login_required], # on every page.
          )

web.add_namespace(server_web)
# web.add_namespace(blocks_web)
# web.add_namespace(control_web)
# web.add_namespace(display_web)
# web.add_namespace(environment_web)
# #web.add_namespace(home_web)
# web.add_namespace(init_web)
# web.add_namespace(other_web)
# web.add_namespace(templates_web)
# web.add_namespace(testfulvio_web)
# web.add_namespace(webcam_web)
