from dataclasses import dataclass

@dataclass
class TranslationResult:
    """
    Structured result from a translator.

    backend_kwargs: arguments passed directly to the backend engine
    wrapper_kwargs: metadata/flags for the local engine wrapper
    """
    backend_kwargs: dict
    wrapper_kwargs: dict

    def merge(self, other: "TranslationResult") -> "TranslationResult":
        # Merge overrides
        def deep_update(d, u):
            for k, v in u.items():
                if isinstance(v, dict) and isinstance(d.get(k), dict):
                    deep_update(d[k], v)
                else:
                    d[k] = v
            return d
        return TranslationResult(
            deep_update(self.backend_kwargs, other.backend_kwargs),
            deep_update(self.wrapper_kwargs, other.wrapper_kwargs)
        )

def translate_all(translator, default_backend_kwargs, user_kwargs):
    final_result = TranslationResult(backend_kwargs=default_backend_kwargs, wrapper_kwargs={})
    for arg_name, arg_val in user_kwargs.items():
        result = translator.translate(arg_name, arg_val)
        if result:
            final_result = final_result.merge(result)
    return final_result.backend_kwargs, final_result.wrapper_kwargs
