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

from flask import render_template, make_response, request, Response, stream_with_context
from flask_restx import Namespace, Resource

from .data_access_object import ObservationBlockObject as DAO
from .data_access_object import guess

from loguru import logger
# adjusted flask_logger
import time
from astropy.time import Time
import json


dao = DAO("ob")
tpl = DAO("defaults")

############################
# REST API
############################

api = Namespace('logger', description='Logger')


@api.route("/")
class Logger(Resource):
    """Show and create OBs"""

    def get(self):
        return make_response(render_template("per-orso.html"))
        # return "ppp"
        # def generate():
        #     while True:
        #         content = Time.now().isot
        #         yield str(content)
        #         time.sleep(1)
        # return Response(stream_with_context(generate()))

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


web = Namespace('logger', description='OB generator')


@web.route("/")
class Logger(Resource):
    """Show and create OBs"""

    def get(self):
        return make_response(render_template("per-orso.html"))

# @web.route("/")
# class BlockListWeb(Resource):
#     """Show and create OBs"""

#     def get(self):
#         """Show all observation OB files"""
#         data = dao.todos
#         return make_response(render_template("ob_list.html", data=data, tpl=tpl.todos))

    # def post(self):
    #     """Create a new OB file based on name"""
    #     name = api.payload
    #     dao.create(name)
    #     return "", 204

    # def delete(self):
    #     """Delete an OB file based on name"""
    #     name = api.payload
    #     dao.delete(name)
    #     return "", 204
