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

from fastapi import (
    APIRouter,
    Body,
    Depends,
    Path,
)
from generated.example.create_widget_input import CreateWidgetInput
from generated.example.widget_create_request import WidgetCreateRequest
from generated.example.widget_summary import WidgetSummary
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.post(
    "/widgets",
    responses={
        201: {"description": "Response"},
    },
    response_model_by_alias=True,
)
async def create_widget(
    services: Annotated[ApiServices, Depends(get_api_services)],
    body: WidgetCreateRequest = Body(...),
) -> WidgetSummary:
    return dispatch_api_response(
        await services.widgets_api.create_widget(create_widget_input=CreateWidgetInput(body=body)),
        OPERATION_HTTP_BINDINGS["create_widget"],
    )


@router.get(
    "/widgets/{widgetId}",
    responses={
        200: {"description": "Response"},
    },
    response_model_by_alias=True,
)
async def get_widget(
    services: Annotated[ApiServices, Depends(get_api_services)],
    widget_id: str = Path(..., alias="widgetId"),
) -> WidgetSummary:
    return dispatch_api_response(
        await services.widgets_api.get_widget(widget_id=widget_id),
        OPERATION_HTTP_BINDINGS["get_widget"],
    )
