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

# Third-party modules
from flask_restx import Namespace, Resource

# Custom modules
from .data_access_object import ObservationBlockObject
from .data_access_object import guess

api = Namespace('block', description='An Observation block')

@api.route("/<path:obname>")
class TodoListApi(Resource):
    
    def get(self, obname):
        obo = ObservationBlockObject("ob/"+obname+".json")
        return obo.todos

    def put(self, obname):
        obo = ObservationBlockObject("ob/"+obname+".json")
        data = api.payload
        for d in data:
            for key,val in d["params"].items():
                d["params"][key] = guess(val)

        return obo.update(data), 201
