# -*- encoding: utf-8 -*-

from typing import Callable
from typing import Dict
from typing import Any


class KeywordArgumentsCloner(object):
    def __init__(self, **kwargs_changes: Dict[str, str]):
        for oldkw, newkw in kwargs_changes.items():
            assert isinstance(oldkw, str)
            assert isinstance(newkw, str)
        self.kwargs_changes = kwargs_changes

    def __call__(self, c):
        return KeywordArgumentsClonerConfigured(c, **self.kwargs_changes)


class KeywordArgumentsClonerConfigured(object):  # Don't instantiate this class manually
    def __init__(self, clb: Callable, **kwargs_changes: Dict[str, str]):
        self.kwargs_changes = kwargs_changes
        self.callback = clb
    
    def __call__(self, *args, **kwargs):
        newkwargs = kwargs.copy()
        for dst, src in self.kwargs_changes.items():
            newkwargs[dst] = newkwargs.get(src, None)
        return self.callback(*args, **newkwargs)