# Path: rest_framework_json_schema/filters.py
# def get_query_filters(
#     params: Dict[str, Any], transformer: Optional[Transform] = None
# ) -> Dict[str, Any]:
#     """
#     Parse JSON API filter query parameters and apply an optional transformation.
# 
#     https://jsonapi.org/format/#fetching-filtering
#     """
# 
#     result = {}
#     transformer = transformer or NullTransform()
# 
#     for key, value in params.items():
#         m = FILTER.match(key)
#         if m:
#             result[transformer.transform(m.group(1))] = value
# 
#     return result
# 
# Path: rest_framework_json_schema/transforms.py
# class CamelCaseToUnderscoreTransform(Transform):
#     """Transform camelCase to snake_underscore_case."""
# 
#     def transform(self, name: str) -> str:
#         """Transform camelCase to snake_underscore_case."""
#         words: List[str] = []
#         last = 0
# 
#         for i, c in enumerate(name):
#             if c[0].isupper():
#                 # Start of a new word
#                 words.append(name[last].lower() + name[last + 1 : i])
#                 last = i
#         # Add the last word
#         words.append(name[last].lower() + name[last + 1 :])
# 
#         return "_".join(words)


from rest_framework_json_schema.filters import get_query_filters
from rest_framework_json_schema.transforms import CamelCaseToUnderscoreTransform


def test_filter_no_transform() -> None:
    """The transform works with no filter."""
    result = get_query_filters(
        {"filter[name]": "John", "filter[lastName]": "Coltrane", "limit": 50}
    )
    assert result == {"name": "John", "lastName": "Coltrane"}


def test_filter_transform() -> None:
    """Given a transform, the filter applies correctly."""

# Path: rest_framework_json_schema/filters.py
# def get_query_filters(
#     params: Dict[str, Any], transformer: Optional[Transform] = None
# ) -> Dict[str, Any]:
#     """
#     Parse JSON API filter query parameters and apply an optional transformation.
# 
#     https://jsonapi.org/format/#fetching-filtering
#     """
# 
#     result = {}
#     transformer = transformer or NullTransform()
# 
#     for key, value in params.items():
#         m = FILTER.match(key)
#         if m:
#             result[transformer.transform(m.group(1))] = value
# 
#     return result
# 
# Path: rest_framework_json_schema/transforms.py
# class CamelCaseToUnderscoreTransform(Transform):
#     """Transform camelCase to snake_underscore_case."""
# 
#     def transform(self, name: str) -> str:
#         """Transform camelCase to snake_underscore_case."""
#         words: List[str] = []
#         last = 0
# 
#         for i, c in enumerate(name):
#             if c[0].isupper():
#                 # Start of a new word
#                 words.append(name[last].lower() + name[last + 1 : i])
#                 last = i
#         # Add the last word
#         words.append(name[last].lower() + name[last + 1 :])
# 
#         return "_".join(words)


# Path: tests/test_filters.py
from rest_framework_json_schema.filters import get_query_filters
from rest_framework_json_schema.transforms import CamelCaseToUnderscoreTransform



def test_filter_no_transform() -> None:
    """The transform works with no filter."""
    result = get_query_filters(
        {"filter[name]": "John", "filter[lastName]": "Coltrane", "limit": 50}
    )
    assert result == {"name": "John", "lastName": "Coltrane"}


def test_filter_transform() -> None:
    """Given a transform, the filter applies correctly."""

    result = get_query_filters(