{%- if context.has_missing_schema -%}
from typing import Any

{% endif -%}
from blacksmith import HTTPRequest
from whitesmith import {{ ", ".join(context.whitesmith_imports) }}
{% for import_lines in context.extra_import_lines %}
{{ import_lines }}
{%- endfor %}

{% for response_model in context.sorted_response_models %}
from {{response_model.mod}} import {{response_model.name}}
{%- endfor %}
{%- for response_model in context.sorted_response_models %}


class {{response_model.name}}Factory(ModelFactory[{{response_model.name}}]):
    __model__ = {{response_model.name}}

{%- endfor %}
{%- for route in context.routes %}


@router.{{route.http_method|lower}}("{{route.url_pattern}}")
def {{route.python_method}}(
    req: HTTPRequest,
) -> {{route.response_class}}[{% if route.response_model %}{{route.response_model}}{% else %}Any{% endif %}]:
    return {{route.response_class}}(
        {%- if route.response_model -%}
            {%- if route.response_class == "HTTPCollectionResponse" -%}
                [
            {%- endif -%}
            {{route.response_model}}Factory.build()
            {%- if route.response_class == "HTTPCollectionResponse" -%}
                ]
            {%- endif -%}
        {%- endif -%}
    )

{%- endfor %}
{{-"\n"-}}
