# Path: pykintone/model.py
# class kintoneModel(ps.kintoneStructure):
# 
#     def __init__(self):
#         super(kintoneModel, self).__init__()
#         self.record_id = -1
#         self.revision = -1
#         self._property_details.append(ps.PropertyDetail("record_id", field_name="$id"))
#         self._property_details.append(ps.PropertyDetail("revision", field_name="$revision"))
# 
#     @classmethod
#     def record_to_model(cls, record_json):
#         def get_value_and_type(f): return f["value"], f["type"]
#         return cls._deserialize(record_json, get_value_and_type)
# 
#     def to_record(self):
#         def convert_to_key_and_value(field_name, value, property_detail=None):
#             key = field_name
#             formatted = {
#                 "value": value
#             }
#             if field_name in ["$id", "$revision"]:
#                 if value > -1:
#                     key = field_name[1:]  # escape $
#                 else:
#                     key = None
# 
#             return key, formatted
# 
#         return self._serialize(convert_to_key_and_value)
# 
# Path: pykintone/structure.py
# class PropertyDetail(object):
#     def __init__(self, name, field_type=None, sub_type=None, unsent=False, field_name=""):
#         self.name = name
#         self.field_type = field_type
#         self.sub_type = sub_type
#         self.unsent = unsent
#         self.field_name = field_name
# 
#     def to_property_name(self, field_name):
#         if self.field_name == field_name:
#             return self.name
#         else:
#             return field_name
# 
#     def to_field_name(self):
#         if self.field_name:
#             return self.field_name
#         else:
#             return self.name
# 
# class FieldType(Enum):
#     DATE = "DATE"
#     TIME = "TIME"
#     DATETIME = "DATETIME"
#     CREATED_TIME = "CREATED_TIME"
#     UPDATED_TIME = "UPDATED_TIME"
#     USER_SELECT = "USER_SELECT"
#     CREATOR = "CREATOR"
#     MODIFIER = "MODIFIER"
#     FILE = "FILE"
#     RECORD_NUMBER = "RECORD_NUMBER"
#     NUMBER = "NUMBER"
#     SUBTABLE = "SUBTABLE"
#     CALC = "CALC"
#     CATEGORY = "CATEGORY"
#     CHECK_BOX = "CHECK_BOX"
#     DROP_DOWN = "DROP_DOWN"
#     HR = "HR"
#     LABEL = "LABEL"
#     LINK = "LINK"
#     MULTI_LINE_TEXT = "MULTI_LINE_TEXT"
#     MULTI_SELECT = "MULTI_SELECT"
#     RADIO_BUTTON = "RADIO_BUTTON"
#     RICH_TEXT = "RICH_TEXT"
#     SINGLE_LINE_TEXT = "SINGLE_LINE_TEXT"
#     SPACER = "SPACER"
#     STATUS = "STATUS"
#     STATUS_ASSIGNEE = "STATUS_ASSIGNEE"
#     ID = "__ID__"
#     REVISION = "__REVISION__"
#     TIME_STAMP = "__TIME_STAMP__"
#     STRUCTURE = "__STRUCTURE__"


import unittest
import tests.envs as envs
import pykintone
import pykintone.structure_field as sf
        import os
from datetime import datetime
from pykintone.model import kintoneModel
from pykintone.structure import PropertyDetail, FieldType


class TestAppModel(kintoneModel):

    def __init__(self):
        super(TestAppModel, self).__init__()
        self.my_key = ""
        self.stringField = ""
        self.numberField = 0
        self.radio = ""
        self.checkbox = []
        self.dateField = datetime.now()
        self.time = datetime.now()
        self.datetimeField = datetime.now()
        self.user_select = sf.UserSelect()
        self.created_time = None
        self.updated_time = None
        self.creator = None
        self.modifier = None
        self.changeLogs = []
        self.attachfile = sf.File()

        self._property_details.append(PropertyDetail("time", FieldType.TIME))
        self._property_details.append(PropertyDetail("created_time", FieldType.CREATED_TIME, field_name="作成日時", unsent=True))
        self._property_details.append(PropertyDetail("updated_time", FieldType.UPDATED_TIME, field_name="更新日時", unsent=True))
        self._property_details.append(PropertyDetail("creator", FieldType.CREATOR, field_name="作成者", unsent=True))
        self._property_details.append(PropertyDetail("modifier", FieldType.MODIFIER, field_name="更新者", unsent=True))
        self._property_details.append(PropertyDetail("changeLogs", FieldType.SUBTABLE, sub_type=History))



# Path: pykintone/model.py
# class kintoneModel(ps.kintoneStructure):
# 
#     def __init__(self):
#         super(kintoneModel, self).__init__()
#         self.record_id = -1
#         self.revision = -1
#         self._property_details.append(ps.PropertyDetail("record_id", field_name="$id"))
#         self._property_details.append(ps.PropertyDetail("revision", field_name="$revision"))
# 
#     @classmethod
#     def record_to_model(cls, record_json):
#         def get_value_and_type(f): return f["value"], f["type"]
#         return cls._deserialize(record_json, get_value_and_type)
# 
#     def to_record(self):
#         def convert_to_key_and_value(field_name, value, property_detail=None):
#             key = field_name
#             formatted = {
#                 "value": value
#             }
#             if field_name in ["$id", "$revision"]:
#                 if value > -1:
#                     key = field_name[1:]  # escape $
#                 else:
#                     key = None
# 
#             return key, formatted
# 
#         return self._serialize(convert_to_key_and_value)
# 
# Path: pykintone/structure.py
# class PropertyDetail(object):
#     def __init__(self, name, field_type=None, sub_type=None, unsent=False, field_name=""):
#         self.name = name
#         self.field_type = field_type
#         self.sub_type = sub_type
#         self.unsent = unsent
#         self.field_name = field_name
# 
#     def to_property_name(self, field_name):
#         if self.field_name == field_name:
#             return self.name
#         else:
#             return field_name
# 
#     def to_field_name(self):
#         if self.field_name:
#             return self.field_name
#         else:
#             return self.name
# 
# class FieldType(Enum):
#     DATE = "DATE"
#     TIME = "TIME"
#     DATETIME = "DATETIME"
#     CREATED_TIME = "CREATED_TIME"
#     UPDATED_TIME = "UPDATED_TIME"
#     USER_SELECT = "USER_SELECT"
#     CREATOR = "CREATOR"
#     MODIFIER = "MODIFIER"
#     FILE = "FILE"
#     RECORD_NUMBER = "RECORD_NUMBER"
#     NUMBER = "NUMBER"
#     SUBTABLE = "SUBTABLE"
#     CALC = "CALC"
#     CATEGORY = "CATEGORY"
#     CHECK_BOX = "CHECK_BOX"
#     DROP_DOWN = "DROP_DOWN"
#     HR = "HR"
#     LABEL = "LABEL"
#     LINK = "LINK"
#     MULTI_LINE_TEXT = "MULTI_LINE_TEXT"
#     MULTI_SELECT = "MULTI_SELECT"
#     RADIO_BUTTON = "RADIO_BUTTON"
#     RICH_TEXT = "RICH_TEXT"
#     SINGLE_LINE_TEXT = "SINGLE_LINE_TEXT"
#     SPACER = "SPACER"
#     STATUS = "STATUS"
#     STATUS_ASSIGNEE = "STATUS_ASSIGNEE"
#     ID = "__ID__"
#     REVISION = "__REVISION__"
#     TIME_STAMP = "__TIME_STAMP__"
#     STRUCTURE = "__STRUCTURE__"


# Path: tests/test_model.py
import unittest
import tests.envs as envs
import pykintone
import pykintone.structure_field as sf
        import os
from datetime import datetime
from pykintone.model import kintoneModel
from pykintone.structure import PropertyDetail, FieldType



class TestAppModel(kintoneModel):

    def __init__(self):
        super(TestAppModel, self).__init__()
        self.my_key = ""
        self.stringField = ""
        self.numberField = 0
        self.radio = ""
        self.checkbox = []
        self.dateField = datetime.now()
        self.time = datetime.now()
        self.datetimeField = datetime.now()
        self.user_select = sf.UserSelect()
        self.created_time = None
        self.updated_time = None
        self.creator = None
        self.modifier = None
        self.changeLogs = []
        self.attachfile = sf.File()

        self._property_details.append(PropertyDetail("time", FieldType.TIME))
        self._property_details.append(PropertyDetail("created_time", FieldType.CREATED_TIME, field_name="作成日時", unsent=True))
        self._property_details.append(PropertyDetail("updated_time", FieldType.UPDATED_TIME, field_name="更新日時", unsent=True))
        self._property_details.append(PropertyDetail("creator", FieldType.CREATOR, field_name="作成者", unsent=True))
        self._property_details.append(PropertyDetail("modifier", FieldType.MODIFIER, field_name="更新者", unsent=True))
        self._property_details.append(PropertyDetail("changeLogs", FieldType.SUBTABLE, sub_type=History))



class History(kintoneModel):