# Path: backend/components/base_component.py
# class BaseComponent(object):
#     """Base component for all system components It stores id type name and trivial string representation"""
#     column_headers_and_types = [['id', 'integer primary key'],
#                                 ['type', 'integer'],
#                                 ['name', 'text'], ]
#     COL_ID, COL_TYPE, COL_NAME = 0, 1, 2  # numery kolumn
# 
#     def __init__(self, *args):
#         self.id, self.type, self.name = args
# 
#         #if not isinstance(self.id, int):
#         #   raise TypeError("Id must be int")
# 
#         if not (isinstance(self.type, int) or isinstance(self.type, Enum)):
#             raise TypeError("Type must be int or enum")
# 
#         if not isinstance(self.name, str):
#             raise TypeError("name must be str")
# 
#         #if self.id < 0:
#         #    raise ValueError("Component id must be positive number")
# 
#     def __str__(self, ):
#         """Representation of object"""
#         return "".join(["ID: ", str(self.id), "\ttype: ", self.type.name, "\tname: ", self.name])
# 
#     def __repr__(self,):
#         return "".join(["ID: ", str(self.id), " type: ", self.type.name])
# 
# Path: backend/misc/sys_types.py
# class Et(AutoNumber):
#     ds = ()
#     dht = ()
#     dht_temp = ()
#     dht_hum = ()
#     led = ()
#     pir = ()
#     rs = ()
#     heater = ()
#     ls = ()
#     ventilator = ()
#     blind = ()
#     switch = ()
# 
# class Regt(AutoNumber):
#     temp = ()
#     hum = ()


from backend.components.base_component import BaseComponent
from backend.misc.sys_types import Et, Regt
from dominate.tags import div, button, h4, span, b, p, input, label
from functools import wraps
def field(func):
    @wraps(func) 
    def func_wrapper(*args, **kwargs):
        field = span(cls = "field")
        field_name = div(b(args[0].name), cls = "text-center")
        field_value = func(args[0])
        field.add(field_name, field_value)
        return field
    return func_wrapper

class Visual_element(BaseComponent):

    table_name = "elements"

    items = {}
    def __init__(self, *args):
        Visual_element.items[args[0]] = self
        if args[0].startswith('r'): #jesli to regulacja. wtedy id jest stringiem i pierwsza litera to r
            super().__init__(args[0], Regt(args[1]), args[2]) # inicjalizuj id type, name
        else:
            super().__init__(args[0], Et(args[1]), args[2]) # inicjalizuj id type, name
        self.value = 0

    def get_html(self,):
        if self.type == Et.blind:
            return self.blind()
        elif self.type in (Et.dht_hum, Et.dht_temp, Et.ds, Et.ls):
            return self.value_field()
        elif self.type in (Regt.hum, Regt.temp):
            return self.input_field()

# Path: backend/components/base_component.py
# class BaseComponent(object):
#     """Base component for all system components It stores id type name and trivial string representation"""
#     column_headers_and_types = [['id', 'integer primary key'],
#                                 ['type', 'integer'],
#                                 ['name', 'text'], ]
#     COL_ID, COL_TYPE, COL_NAME = 0, 1, 2  # numery kolumn
# 
#     def __init__(self, *args):
#         self.id, self.type, self.name = args
# 
#         #if not isinstance(self.id, int):
#         #   raise TypeError("Id must be int")
# 
#         if not (isinstance(self.type, int) or isinstance(self.type, Enum)):
#             raise TypeError("Type must be int or enum")
# 
#         if not isinstance(self.name, str):
#             raise TypeError("name must be str")
# 
#         #if self.id < 0:
#         #    raise ValueError("Component id must be positive number")
# 
#     def __str__(self, ):
#         """Representation of object"""
#         return "".join(["ID: ", str(self.id), "\ttype: ", self.type.name, "\tname: ", self.name])
# 
#     def __repr__(self,):
#         return "".join(["ID: ", str(self.id), " type: ", self.type.name])
# 
# Path: backend/misc/sys_types.py
# class Et(AutoNumber):
#     ds = ()
#     dht = ()
#     dht_temp = ()
#     dht_hum = ()
#     led = ()
#     pir = ()
#     rs = ()
#     heater = ()
#     ls = ()
#     ventilator = ()
#     blind = ()
#     switch = ()
# 
# class Regt(AutoNumber):
#     temp = ()
#     hum = ()


# Path: server_client/server/models/visual_element.py
from backend.components.base_component import BaseComponent
from backend.misc.sys_types import Et, Regt
from dominate.tags import div, button, h4, span, b, p, input, label
from functools import wraps

def field(func):
    @wraps(func) 
    def func_wrapper(*args, **kwargs):
        field = span(cls = "field")
        field_name = div(b(args[0].name), cls = "text-center")
        field_value = func(args[0])
        field.add(field_name, field_value)
        return field
    return func_wrapper

class Visual_element(BaseComponent):

    table_name = "elements"

    items = {}
    def __init__(self, *args):
        Visual_element.items[args[0]] = self
        if args[0].startswith('r'): #jesli to regulacja. wtedy id jest stringiem i pierwsza litera to r
            super().__init__(args[0], Regt(args[1]), args[2]) # inicjalizuj id type, name
        else:
            super().__init__(args[0], Et(args[1]), args[2]) # inicjalizuj id type, name
        self.value = 0

    def get_html(self,):
        if self.type == Et.blind:
            return self.blind()
        elif self.type in (Et.dht_hum, Et.dht_temp, Et.ds, Et.ls):
            return self.value_field()
        elif self.type in (Regt.hum, Regt.temp):
            return self.input_field()

        elif self.type in (Et.heater, Et.pir, Et.rs, Et.switch):