from abc import ABC, abstractmethod
from typing import List, TypeVar

T = TypeVar("T")


class Sanitizer(ABC):
    @abstractmethod
    def _types_to_sanitize(self) -> List[type]:
        return []

    @abstractmethod
    def _sanitize(self, value):
        raise NotImplementedError()

    def sanitize(self, value: T) -> T:
        if type(value) in self._types_to_sanitize():
            return self._sanitize(value)
        return value

    def sanitize_request(self, value: T) -> T:
        return self.sanitize(value)

    def sanitize_response(self, value: T) -> T:
        return self.sanitize(value)
