from cuchulu.libraries.db import corefields
from cuchulu.libraries.db.extrafields.jsonfield import JsonField
from cuchulu.libraries.db.extrafields.dictfield import DictField
try:
    import ujson as json
except:
    import json

"""A class for list objects with data fields
"""

class ListItem:
    pass
    
"""Typical item """

class Items(ListItem):
    
    name=corefields.CharField('name')
        

class StandardResponse:
    
    error=corefields.BooleanField('error')
    message=corefields.CharField('message')
    code_error=corefields.IntegerField('code_error')
    error_form=DictField('error_form', corefields.CharField('error_form'))
    #items=JsonField('items', corefields.CharField)
    
    def __init__(self, error=0, message='', code_error=0):

        self.error=error
        self.message=message
        self.code_error=code_error
    
    def toDict(self):
        
        return self.__dict__
    
    def toJSON(self):
        return json.dumps( self, default=lambda o: o.__dict__, sort_keys=True, indent=4 )



class ResponseItems(StandardResponse):
    pass
    
