# (c) cavaliba.com - data - field - string

"""
FieldString: dataformat "string", the default/fallback field type. dataformat_ext
"safe" displays unescaped, "url" displays as a link in detail views.

Method inventory: merge_import, is_valid.
"""

from .field import Field

# -------------
# STRING
# -------------

# dataformat_ext:
# - safe : display unescaped
# - url  : display as <a> link in detail


class FieldString(Field):
    # def __init__(self, fieldname, fieldschema, alljson):
    #     super().__init__(fieldname, fieldschema, alljson)

    #     # if no json, unpack default_value
    #     if not alljson:
    #         if self.default_value:
    #             self.value = self.default_value

    def merge_import(self, data):
        """Set self.value from an import/API payload as-is (no split_composite)."""
        # no split composite !
        self.value = []
        if type(data) is str:
            self.value = [data]
        elif type(data) is list:
            for i in data:
                self.value.append(i)

    def is_valid(self):
        """Cardinality check (super) only; no string-specific validation yet."""
        r = super().is_valid()
        # TODO
        return r
