# Generated by oapi-gen. DO NOT EDIT.
from pathlib import Path

from msgspec import json
from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import Route, Router

from .contracts import Handlers
from .routes.cats import create_routes as _routes_cats


def create_router(handlers: Handlers, *, prefix: str = "", include_schema: bool = True) -> Router:
    __oapi_by_path: dict[tuple[str, str], Route] = {}
    __oapi_by_path.update(_routes_cats(handlers.cats, prefix=prefix))
    __oapi_routes = [__oapi_by_path[key] for key in sorted(__oapi_by_path)]
    if include_schema:
        __oapi_schema = json.decode(Path(__file__).with_name("openapi.json").read_bytes())
        __oapi_schema["paths"] = {
            prefix + path: item for path, item in __oapi_schema["paths"].items()
        }
        __oapi_schema_bytes = json.encode(__oapi_schema)

        async def __oapi_openapi(request: Request) -> Response:
            return Response(__oapi_schema_bytes, media_type="application/json")

        __oapi_routes.append(Route(prefix + "/openapi.json", __oapi_openapi))
    return Router(routes=__oapi_routes)
