# Path: pykintone/structure.py
# 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: pykintone/application_settings/base_administration_api.py
# class BaseAdministrationAPI(BaseAPI):
# 
#     def __init__(self, account, api_token="", requests_options=(), app_id=""):
#         super(BaseAdministrationAPI, self).__init__(account, api_token, requests_options, app_id)
#         self.__test_mode = False
#         self._commit_revision = -1
#         self._cached_changes = False
# 
#     def as_test_mode(self):
#         self.__test_mode = True
#         return self
# 
#     def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
#         result = super(BaseAdministrationAPI, self)._request(method, url, params_or_data, headers, use_api_token)
#         if method in ("POST", "PUT", "DELETE"):
#             self._cached_changes = True
#         return result
# 
#     def __enter__(self):
#         self._commit_revision = -1
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         if self._cached_changes and not self.app_id:
#             raise Exception("There are some changes to be committed, but no application id.")
#         elif not (self._cached_changes and self.app_id):
#             return None
# 
#         admin = self.__get_admin()
#         result = None
#         exit_type = "Commit"
#         if exc_type is None and not self.__test_mode:
#             result = admin.commit_settings(self.app_id, self._commit_revision)
#         else:
#             exit_type = "Rollback"
#             result = admin.rollback_settings(self.app_id, self._commit_revision)
# 
#         if result.ok:
#             self._commit_revision = -1
#             self._cached_changes = False
#         else:
#             raise Exception(exit_type + " failed. {0}".format(result.message))
# 
#     def __get_admin(self):
#         from pykintone.application_settings.administrator import Administrator
#         admin = Administrator(self.account, self.api_token, self.requests_options, self.app_id)
#         return admin
# 
# Path: pykintone/application_settings/form_layout.py
# class Layout(ps.kintoneStructure):
# 
#     def __init__(self):
#         super(Layout, self).__init__()
#         self.layout_type = "ROW"
#         self.code = ""
#         self.fields = [LayoutField]
#         self._property_details.append(ps.PropertyDetail("layout_type", field_name="type"))
# 
#     @classmethod
#     def create(cls, fields, layout_type="", code=""):
#         instance = Layout()
#         instance.layout_type = layout_type if layout_type else instance.layout_type
#         instance.code = code if code else instance.code
# 
#         if not (isinstance(fields, (list, tuple)) and len(fields) > 0):
#             raise Exception("Layout fields have to be array, and it must have at least one field.")
# 
#         def convert(f):
#             if isinstance(f, LayoutField):
#                 return f
#             elif isinstance(f, (list, tuple)):
#                 return LayoutField.create(*f)
#             elif isinstance(f, dict):
#                 return LayoutField.create(**f)
#             else:
#                 return LayoutField.create(f)
# 
#         fs = [convert(f) for f in fields]
#         instance.fields = fs
#         return instance
# 
#     def serialize(self):
#         return self._serialize(lambda name, value, pd: (name, value), ignore_missing=True)
# 
#     @classmethod
#     def deserialize(cls, json_body):
#         return cls._deserialize(json_body, lambda f: (f, ""))


from pykintone.structure import FieldType
from pykintone.application_settings.base_administration_api import BaseAdministrationAPI
from pykintone.application_settings.form_layout import Layout
import pykintone.application_settings.form_field as ff
import pykintone.application_settings.setting_result as sr
            st = serialize(t)
            if "code" in st and "type" in st:
                properties[st["code"]] = st

        formatted = {"properties": properties}
        envelope = self.__pack(formatted, app_id, revision)

        return envelope

    def __pack(self, pack, app_id="", revision=-1):
        _p = pack.copy()
        _p["app"] = app_id if app_id else self.app_id
        if revision > -1:
            _p["revision"] = revision

        return _p

    @classmethod
    def load_properties(cls, properties):
        fields = []
        for k in properties:
            p = properties[k]
            field_type = None
            field_name = p["type"].upper()
            candidates = [e for e in list(FieldType) if e.value == field_name]
            if len(candidates) > 0:
                field_type = candidates[0]

            if not field_type:
                pass

# Path: pykintone/structure.py
# 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: pykintone/application_settings/base_administration_api.py
# class BaseAdministrationAPI(BaseAPI):
# 
#     def __init__(self, account, api_token="", requests_options=(), app_id=""):
#         super(BaseAdministrationAPI, self).__init__(account, api_token, requests_options, app_id)
#         self.__test_mode = False
#         self._commit_revision = -1
#         self._cached_changes = False
# 
#     def as_test_mode(self):
#         self.__test_mode = True
#         return self
# 
#     def _request(self, method, url, params_or_data, headers=None, use_api_token=True):
#         result = super(BaseAdministrationAPI, self)._request(method, url, params_or_data, headers, use_api_token)
#         if method in ("POST", "PUT", "DELETE"):
#             self._cached_changes = True
#         return result
# 
#     def __enter__(self):
#         self._commit_revision = -1
#         return self
# 
#     def __exit__(self, exc_type, exc_val, exc_tb):
#         if self._cached_changes and not self.app_id:
#             raise Exception("There are some changes to be committed, but no application id.")
#         elif not (self._cached_changes and self.app_id):
#             return None
# 
#         admin = self.__get_admin()
#         result = None
#         exit_type = "Commit"
#         if exc_type is None and not self.__test_mode:
#             result = admin.commit_settings(self.app_id, self._commit_revision)
#         else:
#             exit_type = "Rollback"
#             result = admin.rollback_settings(self.app_id, self._commit_revision)
# 
#         if result.ok:
#             self._commit_revision = -1
#             self._cached_changes = False
#         else:
#             raise Exception(exit_type + " failed. {0}".format(result.message))
# 
#     def __get_admin(self):
#         from pykintone.application_settings.administrator import Administrator
#         admin = Administrator(self.account, self.api_token, self.requests_options, self.app_id)
#         return admin
# 
# Path: pykintone/application_settings/form_layout.py
# class Layout(ps.kintoneStructure):
# 
#     def __init__(self):
#         super(Layout, self).__init__()
#         self.layout_type = "ROW"
#         self.code = ""
#         self.fields = [LayoutField]
#         self._property_details.append(ps.PropertyDetail("layout_type", field_name="type"))
# 
#     @classmethod
#     def create(cls, fields, layout_type="", code=""):
#         instance = Layout()
#         instance.layout_type = layout_type if layout_type else instance.layout_type
#         instance.code = code if code else instance.code
# 
#         if not (isinstance(fields, (list, tuple)) and len(fields) > 0):
#             raise Exception("Layout fields have to be array, and it must have at least one field.")
# 
#         def convert(f):
#             if isinstance(f, LayoutField):
#                 return f
#             elif isinstance(f, (list, tuple)):
#                 return LayoutField.create(*f)
#             elif isinstance(f, dict):
#                 return LayoutField.create(**f)
#             else:
#                 return LayoutField.create(f)
# 
#         fs = [convert(f) for f in fields]
#         instance.fields = fs
#         return instance
# 
#     def serialize(self):
#         return self._serialize(lambda name, value, pd: (name, value), ignore_missing=True)
# 
#     @classmethod
#     def deserialize(cls, json_body):
#         return cls._deserialize(json_body, lambda f: (f, ""))


# Path: pykintone/application_settings/form.py
from pykintone.structure import FieldType
from pykintone.application_settings.base_administration_api import BaseAdministrationAPI
from pykintone.application_settings.form_layout import Layout
import pykintone.application_settings.form_field as ff
import pykintone.application_settings.setting_result as sr

            st = serialize(t)
            if "code" in st and "type" in st:
                properties[st["code"]] = st

        formatted = {"properties": properties}
        envelope = self.__pack(formatted, app_id, revision)

        return envelope

    def __pack(self, pack, app_id="", revision=-1):
        _p = pack.copy()
        _p["app"] = app_id if app_id else self.app_id
        if revision > -1:
            _p["revision"] = revision

        return _p

    @classmethod
    def load_properties(cls, properties):
        fields = []
        for k in properties:
            p = properties[k]
            field_type = None
            field_name = p["type"].upper()
            candidates = [e for e in list(FieldType) if e.value == field_name]
            if len(candidates) > 0:
                field_type = candidates[0]

            if not field_type:
                pass

            elif field_type == FieldType.LABEL: