import functools
from typing import Generic

from core.typing import T


class Sort(Generic[T]):
    def __init__(self, _t: type, sort: dict):
        for key in sort:
            self.__setattr__(key, sort[key])

    def _rgetattr(self, attr, *args):
        def _getattr(self, attr):
            return getattr(self, attr, *args)

        return functools.reduce(_getattr, [self] + attr.split("."))
