from __future__ import annotations

from typing import Any


class RelationResolver:
    def resolve(self, data: Any, default: str = "is") -> str:
        try:
            relation_value = data.relation
        except AttributeError:
            relation_value = None
        if not relation_value:
            relation_value = default

        if isinstance(relation_value, str) and relation_value:
            return relation_value

        try:
            attr_value = relation_value.value
        except AttributeError:
            attr_value = None
        if isinstance(attr_value, str) and attr_value:
            return attr_value
        try:
            relation_name = relation_value.relation
        except AttributeError:
            relation_name = None
        if isinstance(relation_name, str) and relation_name:
            return relation_name
        try:
            name = relation_value.name
        except AttributeError:
            name = None
        if isinstance(name, str) and name:
            return name

        try:
            nested_value = attr_value.value
        except AttributeError:
            nested_value = None
        if isinstance(nested_value, str) and nested_value:
            return nested_value

        try:
            relationship_phrase = data.relationship_phrase
        except AttributeError:
            relationship_phrase = None
        if isinstance(relationship_phrase, str) and relationship_phrase:
            return relationship_phrase

        return str(relation_value)
