# Path: netvisor/schemas/common.py
# class DateSchema(FlattenElementSchema):
#     text = fields.Date(load_from='#text')
# 
# class StringSchema(FlattenElementSchema):
#     text = fields.String(load_from='#text')
# 
# Path: netvisor/schemas/fields.py
# class List(fields.List):
#     def _deserialize(self, value, attr, data):
#         if not is_collection(value) and value is not None:
#             value = [value]
#         return super(List, self)._deserialize(value, attr, data)


from marshmallow import Schema, fields, post_load
from ..common import DateSchema, StringSchema
from ..fields import List



class Address(Schema):
    street = fields.String(allow_none=True)
    postal_code = fields.String()
    postal_office = fields.String()


class RegisteredName(Schema):
    type = fields.String()
    name = fields.String()
    current_activity_status = fields.String()
    established_date = fields.Nested(DateSchema)
    terminated_date = fields.Nested(DateSchema)


class RegisteredNames(Schema):
    registered_name = List(fields.Nested(RegisteredName))

    @post_load
    def preprocess_registered_names(self, input_data):
        return input_data['registered_name'] if input_data else []


class RegisteredPersonRole(Schema):
    type = fields.String()
    identifier = fields.String()
    established_date = fields.Nested(DateSchema)
    name = fields.String()

# Path: netvisor/schemas/common.py
# class DateSchema(FlattenElementSchema):
#     text = fields.Date(load_from='#text')
# 
# class StringSchema(FlattenElementSchema):
#     text = fields.String(load_from='#text')
# 
# Path: netvisor/schemas/fields.py
# class List(fields.List):
#     def _deserialize(self, value, attr, data):
#         if not is_collection(value) and value is not None:
#             value = [value]
#         return super(List, self)._deserialize(value, attr, data)


# Path: netvisor/schemas/companies/get.py
from marshmallow import Schema, fields, post_load
from ..common import DateSchema, StringSchema
from ..fields import List




class Address(Schema):
    street = fields.String(allow_none=True)
    postal_code = fields.String()
    postal_office = fields.String()


class RegisteredName(Schema):
    type = fields.String()
    name = fields.String()
    current_activity_status = fields.String()
    established_date = fields.Nested(DateSchema)
    terminated_date = fields.Nested(DateSchema)


class RegisteredNames(Schema):
    registered_name = List(fields.Nested(RegisteredName))

    @post_load
    def preprocess_registered_names(self, input_data):
        return input_data['registered_name'] if input_data else []


class RegisteredPersonRole(Schema):
    type = fields.String()
    identifier = fields.String()
    established_date = fields.Nested(DateSchema)
    name = fields.String()

    nationality = fields.Nested(StringSchema)