# Generated by smithplates HTTP codegen. Do not edit.
from typing import Annotated

from fastapi import (
    APIRouter,
    Depends,
    Header,
    Path,
    Query,
)
from generated.example.widget_list_output import WidgetListOutput
from generated.example.widget_output import WidgetOutput
from generated.widget_api.widget_api.api_response import dispatch_api_response
from generated.widget_api.widget_api.app_services import ApiServices, get_api_services
from generated.widget_api.widget_api.operation_bindings import OPERATION_HTTP_BINDINGS
from pydantic import Field  # noqa: F401

router = APIRouter()


@router.get(
    "/v1/widgets/{id}",
    responses={
        200: {"description": "Response"},
    },
    response_model_by_alias=True,
)
async def inspect_widget(
    services: Annotated[ApiServices, Depends(get_api_services)],
    region: str | None = Header(None, alias="X-Region"),
    id_: str = Path(..., alias="id"),
    category: str | None = Query(None, alias="category"),
    since: float | None = Query(None, alias="since"),
) -> WidgetOutput:
    return dispatch_api_response(
        await services.v1_widgets_api.inspect_widget(
            region=region,
            id_=id_,
            category=category,
            since=since,
        ),
        OPERATION_HTTP_BINDINGS["inspect_widget"],
    )


@router.get(
    "/v1/widgets",
    responses={
        200: {"description": "Response"},
    },
    response_model_by_alias=True,
)
async def search_widgets(
    services: Annotated[ApiServices, Depends(get_api_services)],
    trace_id: str | None = Header(None, alias="X-Trace-Id"),
    sort: str | None = Query(None, alias="sort"),
    limit: int | None = Query(None, alias="limit"),
) -> WidgetListOutput:
    return dispatch_api_response(
        await services.v1_widgets_api.search_widgets(
            trace_id=trace_id,
            sort=sort,
            limit=limit,
        ),
        OPERATION_HTTP_BINDINGS["search_widgets"],
    )
