from rest_framework import serializers


class BaseModelSerializerClass(serializers.ModelSerializer):
    custom_exclude_fields_list = [
        'created_by',
        'created_by_user_agent_info',
        'last_updated_by',
        'last_updated_by_user_agent_info',
        'is_deleted',
        'deleted_at',
        'deleted_by',
        'deleted_by_user_agent_info',
        'server_side_settings',
    ]

    def custom_excluder(self, inp):
        if isinstance(inp, list):
            return [self.custom_excluder(i) for i in inp]
        if isinstance(inp, dict):
            tmp = {}
            for k, v in inp.items():
                if k not in self.custom_exclude_fields_list:
                    tmp[k] = self.custom_excluder(v)
            ret = tmp
            return ret
        return inp

    def to_representation(self, instance):
        rslt = super().to_representation(instance)
        return self.custom_excluder(rslt)

    class Meta:
        pass


class BaseCreateModelSerializerClass(BaseModelSerializerClass):
    class Meta(BaseModelSerializerClass.Meta):
        pass


class BaseListModelSerializerClass(BaseModelSerializerClass):
    class Meta(BaseModelSerializerClass.Meta):
        pass


class BaseRetrieveModelSerializerClass(BaseModelSerializerClass):
    class Meta(BaseModelSerializerClass.Meta):
        pass


class BaseUpdateModelSerializerClass(BaseModelSerializerClass):
    class Meta(BaseModelSerializerClass.Meta):
        pass


class BaseDestroyModelSerializerClass(BaseModelSerializerClass):
    class Meta(BaseModelSerializerClass.Meta):
        pass
