//go:build go1.22

// Package generated provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.0 DO NOT EDIT.
package generated

import (
	"context"
	"encoding/json"
	"fmt"
	"net/http"
	"time"

	strictnethttp "github.com/oapi-codegen/runtime/strictmiddleware/nethttp"
	openapi_types "github.com/oapi-codegen/runtime/types"
)

// Defines values for TelegramCallbackHandleHandleKind.
const (
	FreeTextSession TelegramCallbackHandleHandleKind = "free_text_session"
	Option          TelegramCallbackHandleHandleKind = "option"
)

// Defines values for TelegramContinuationPolicyPreferredMode.
const (
	TelegramContinuationPolicyPreferredModeEditInPlaceFirst TelegramContinuationPolicyPreferredMode = "edit_in_place_first"
	TelegramContinuationPolicyPreferredModeFollowUpOnly     TelegramContinuationPolicyPreferredMode = "follow_up_only"
)

// Defines values for TelegramInteractionContentNotificationKind.
const (
	Completion   TelegramInteractionContentNotificationKind = "completion"
	NextStep     TelegramInteractionContentNotificationKind = "next_step"
	StatusUpdate TelegramInteractionContentNotificationKind = "status_update"
	Warning      TelegramInteractionContentNotificationKind = "warning"
)

// Defines values for TelegramInteractionContinuationAction.
const (
	EditMessage  TelegramInteractionContinuationAction = "edit_message"
	SendFollowUp TelegramInteractionContinuationAction = "send_follow_up"
)

// Defines values for TelegramInteractionContinuationReason.
const (
	AppliedResponse  TelegramInteractionContinuationReason = "applied_response"
	EditFailed       TelegramInteractionContinuationReason = "edit_failed"
	ExpiredWait      TelegramInteractionContinuationReason = "expired_wait"
	OperatorFallback TelegramInteractionContinuationReason = "operator_fallback"
)

// Defines values for TelegramInteractionContinuationResolutionKind.
const (
	DeliveryOnly      TelegramInteractionContinuationResolutionKind = "delivery_only"
	FreeTextSubmitted TelegramInteractionContinuationResolutionKind = "free_text_submitted"
	OptionSelected    TelegramInteractionContinuationResolutionKind = "option_selected"
)

// Defines values for TelegramInteractionDeliveryEnvelopeDeliveryRole.
const (
	FollowUpNotify  TelegramInteractionDeliveryEnvelopeDeliveryRole = "follow_up_notify"
	MessageEdit     TelegramInteractionDeliveryEnvelopeDeliveryRole = "message_edit"
	PrimaryDispatch TelegramInteractionDeliveryEnvelopeDeliveryRole = "primary_dispatch"
)

// Defines values for TelegramInteractionDeliveryEnvelopeInteractionKind.
const (
	DecisionRequest TelegramInteractionDeliveryEnvelopeInteractionKind = "decision_request"
	Notify          TelegramInteractionDeliveryEnvelopeInteractionKind = "notify"
)

// Defines values for TelegramInteractionDeliveryEnvelopeSchemaVersion.
const (
	TelegramInteractionV1 TelegramInteractionDeliveryEnvelopeSchemaVersion = "telegram-interaction-v1"
)

// Defines values for TelegramInteractionDeliveryResponseEditCapability.
const (
	TelegramInteractionDeliveryResponseEditCapabilityFollowUpOnly TelegramInteractionDeliveryResponseEditCapability = "follow_up_only"
	TelegramInteractionDeliveryResponseEditCapabilityKeyboardOnly TelegramInteractionDeliveryResponseEditCapability = "keyboard_only"
	TelegramInteractionDeliveryResponseEditCapabilityUnknown      TelegramInteractionDeliveryResponseEditCapability = "unknown"
)

// InteractionContextLinks defines model for InteractionContextLinks.
type InteractionContextLinks struct {
	IssueUrl           *string `json:"issue_url,omitempty"`
	PullRequestUrl     *string `json:"pull_request_url,omitempty"`
	RepositoryFullName *string `json:"repository_full_name,omitempty"`
	RunId              string  `json:"run_id"`
	RunUrl             *string `json:"run_url,omitempty"`
}

// TelegramCallbackEndpoint defines model for TelegramCallbackEndpoint.
type TelegramCallbackEndpoint struct {
	BearerToken    string                   `json:"bearer_token"`
	Handles        []TelegramCallbackHandle `json:"handles"`
	TokenExpiresAt time.Time                `json:"token_expires_at"`
	Url            string                   `json:"url"`
}

// TelegramCallbackHandle defines model for TelegramCallbackHandle.
type TelegramCallbackHandle struct {
	ButtonLabel *string                          `json:"button_label,omitempty"`
	ExpiresAt   time.Time                        `json:"expires_at"`
	Handle      string                           `json:"handle"`
	HandleKind  TelegramCallbackHandleHandleKind `json:"handle_kind"`
	OptionId    *string                          `json:"option_id,omitempty"`
}

// TelegramCallbackHandleHandleKind defines model for TelegramCallbackHandle.HandleKind.
type TelegramCallbackHandleHandleKind string

// TelegramContinuationPolicy defines model for TelegramContinuationPolicy.
type TelegramContinuationPolicy struct {
	DisableKeyboardOnResolution     bool                                    `json:"disable_keyboard_on_resolution"`
	ManualFallbackOnFollowUpFailure bool                                    `json:"manual_fallback_on_follow_up_failure"`
	PreferredMode                   TelegramContinuationPolicyPreferredMode `json:"preferred_mode"`
	SendFollowUpOnEditFailure       bool                                    `json:"send_follow_up_on_edit_failure"`
}

// TelegramContinuationPolicyPreferredMode defines model for TelegramContinuationPolicy.PreferredMode.
type TelegramContinuationPolicyPreferredMode string

// TelegramDecisionOption defines model for TelegramDecisionOption.
type TelegramDecisionOption struct {
	CallbackHandle string  `json:"callback_handle"`
	Description    *string `json:"description,omitempty"`
	Label          string  `json:"label"`
	OptionId       string  `json:"option_id"`
}

// TelegramInteractionContent defines model for TelegramInteractionContent.
type TelegramInteractionContent struct {
	ActionLabel         *string                                     `json:"action_label,omitempty"`
	ActionUrl           *string                                     `json:"action_url,omitempty"`
	AllowFreeText       *bool                                       `json:"allow_free_text,omitempty"`
	DetailsMarkdown     *string                                     `json:"details_markdown,omitempty"`
	ExpiresAt           *time.Time                                  `json:"expires_at,omitempty"`
	FreeTextPlaceholder *string                                     `json:"free_text_placeholder,omitempty"`
	NotificationKind    *TelegramInteractionContentNotificationKind `json:"notification_kind,omitempty"`
	Options             *[]TelegramDecisionOption                   `json:"options,omitempty"`
	Question            *string                                     `json:"question,omitempty"`
	ReplyInstruction    *string                                     `json:"reply_instruction,omitempty"`
	Summary             *string                                     `json:"summary,omitempty"`
}

// TelegramInteractionContentNotificationKind defines model for TelegramInteractionContent.NotificationKind.
type TelegramInteractionContentNotificationKind string

// TelegramInteractionContinuation defines model for TelegramInteractionContinuation.
type TelegramInteractionContinuation struct {
	Action         TelegramInteractionContinuationAction          `json:"action"`
	Reason         *TelegramInteractionContinuationReason         `json:"reason,omitempty"`
	ResolutionKind *TelegramInteractionContinuationResolutionKind `json:"resolution_kind,omitempty"`
	ResolvedAt     *time.Time                                     `json:"resolved_at,omitempty"`
}

// TelegramInteractionContinuationAction defines model for TelegramInteractionContinuation.Action.
type TelegramInteractionContinuationAction string

// TelegramInteractionContinuationReason defines model for TelegramInteractionContinuation.Reason.
type TelegramInteractionContinuationReason string

// TelegramInteractionContinuationResolutionKind defines model for TelegramInteractionContinuation.ResolutionKind.
type TelegramInteractionContinuationResolutionKind string

// TelegramInteractionDeliveryEnvelope defines model for TelegramInteractionDeliveryEnvelope.
type TelegramInteractionDeliveryEnvelope struct {
	CallbackEndpoint   *TelegramCallbackEndpoint                          `json:"callback_endpoint,omitempty"`
	Content            *TelegramInteractionContent                        `json:"content,omitempty"`
	ContextLinks       InteractionContextLinks                            `json:"context_links"`
	Continuation       *TelegramInteractionContinuation                   `json:"continuation,omitempty"`
	ContinuationPolicy TelegramContinuationPolicy                         `json:"continuation_policy"`
	DeliveryDeadlineAt *time.Time                                         `json:"delivery_deadline_at,omitempty"`
	DeliveryId         openapi_types.UUID                                 `json:"delivery_id"`
	DeliveryRole       TelegramInteractionDeliveryEnvelopeDeliveryRole    `json:"delivery_role"`
	InteractionId      openapi_types.UUID                                 `json:"interaction_id"`
	InteractionKind    TelegramInteractionDeliveryEnvelopeInteractionKind `json:"interaction_kind"`
	Locale             *string                                            `json:"locale,omitempty"`
	ProviderMessageRef *TelegramProviderMessageRef                        `json:"provider_message_ref,omitempty"`
	RecipientProvider  string                                             `json:"recipient_provider"`
	RecipientRef       string                                             `json:"recipient_ref"`
	SchemaVersion      TelegramInteractionDeliveryEnvelopeSchemaVersion   `json:"schema_version"`
}

// TelegramInteractionDeliveryEnvelopeDeliveryRole defines model for TelegramInteractionDeliveryEnvelope.DeliveryRole.
type TelegramInteractionDeliveryEnvelopeDeliveryRole string

// TelegramInteractionDeliveryEnvelopeInteractionKind defines model for TelegramInteractionDeliveryEnvelope.InteractionKind.
type TelegramInteractionDeliveryEnvelopeInteractionKind string

// TelegramInteractionDeliveryEnvelopeSchemaVersion defines model for TelegramInteractionDeliveryEnvelope.SchemaVersion.
type TelegramInteractionDeliveryEnvelopeSchemaVersion string

// TelegramInteractionDeliveryResponse defines model for TelegramInteractionDeliveryResponse.
type TelegramInteractionDeliveryResponse struct {
	Accepted           bool                                               `json:"accepted"`
	AdapterDeliveryId  *string                                            `json:"adapter_delivery_id,omitempty"`
	EditCapability     *TelegramInteractionDeliveryResponseEditCapability `json:"edit_capability,omitempty"`
	Message            *string                                            `json:"message,omitempty"`
	ProviderMessageRef *TelegramProviderMessageRef                        `json:"provider_message_ref,omitempty"`
	Retryable          bool                                               `json:"retryable"`
}

// TelegramInteractionDeliveryResponseEditCapability defines model for TelegramInteractionDeliveryResponse.EditCapability.
type TelegramInteractionDeliveryResponseEditCapability string

// TelegramProviderMessageRef defines model for TelegramProviderMessageRef.
type TelegramProviderMessageRef struct {
	ChatRef         *string    `json:"chat_ref,omitempty"`
	InlineMessageId *string    `json:"inline_message_id,omitempty"`
	MessageId       *string    `json:"message_id,omitempty"`
	SentAt          *time.Time `json:"sent_at,omitempty"`
}

// TelegramWebhookUpdate defines model for TelegramWebhookUpdate.
type TelegramWebhookUpdate map[string]interface{}

// PostTelegramInteractionWebhookJSONRequestBody defines body for PostTelegramInteractionWebhook for application/json ContentType.
type PostTelegramInteractionWebhookJSONRequestBody = TelegramWebhookUpdate

// PostTelegramInteractionDeliveryJSONRequestBody defines body for PostTelegramInteractionDelivery for application/json ContentType.
type PostTelegramInteractionDeliveryJSONRequestBody = TelegramInteractionDeliveryEnvelope

// ServerInterface represents all server handlers.
type ServerInterface interface {
	// Receive one raw Telegram webhook update
	// (POST /api/v1/telegram/interactions/webhook)
	PostTelegramInteractionWebhook(w http.ResponseWriter, r *http.Request)
	// Accept one Telegram interaction delivery envelope from worker
	// (POST /v1/telegram/interaction-deliveries)
	PostTelegramInteractionDelivery(w http.ResponseWriter, r *http.Request)
}

// ServerInterfaceWrapper converts contexts to parameters.
type ServerInterfaceWrapper struct {
	Handler            ServerInterface
	HandlerMiddlewares []MiddlewareFunc
	ErrorHandlerFunc   func(w http.ResponseWriter, r *http.Request, err error)
}

type MiddlewareFunc func(http.Handler) http.Handler

// PostTelegramInteractionWebhook operation middleware
func (siw *ServerInterfaceWrapper) PostTelegramInteractionWebhook(w http.ResponseWriter, r *http.Request) {

	handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		siw.Handler.PostTelegramInteractionWebhook(w, r)
	}))

	for _, middleware := range siw.HandlerMiddlewares {
		handler = middleware(handler)
	}

	handler.ServeHTTP(w, r)
}

// PostTelegramInteractionDelivery operation middleware
func (siw *ServerInterfaceWrapper) PostTelegramInteractionDelivery(w http.ResponseWriter, r *http.Request) {

	handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		siw.Handler.PostTelegramInteractionDelivery(w, r)
	}))

	for _, middleware := range siw.HandlerMiddlewares {
		handler = middleware(handler)
	}

	handler.ServeHTTP(w, r)
}

type UnescapedCookieParamError struct {
	ParamName string
	Err       error
}

func (e *UnescapedCookieParamError) Error() string {
	return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
}

func (e *UnescapedCookieParamError) Unwrap() error {
	return e.Err
}

type UnmarshalingParamError struct {
	ParamName string
	Err       error
}

func (e *UnmarshalingParamError) Error() string {
	return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}

func (e *UnmarshalingParamError) Unwrap() error {
	return e.Err
}

type RequiredParamError struct {
	ParamName string
}

func (e *RequiredParamError) Error() string {
	return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
}

type RequiredHeaderError struct {
	ParamName string
	Err       error
}

func (e *RequiredHeaderError) Error() string {
	return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
}

func (e *RequiredHeaderError) Unwrap() error {
	return e.Err
}

type InvalidParamFormatError struct {
	ParamName string
	Err       error
}

func (e *InvalidParamFormatError) Error() string {
	return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
}

func (e *InvalidParamFormatError) Unwrap() error {
	return e.Err
}

type TooManyValuesForParamError struct {
	ParamName string
	Count     int
}

func (e *TooManyValuesForParamError) Error() string {
	return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
}

// Handler creates http.Handler with routing matching OpenAPI spec.
func Handler(si ServerInterface) http.Handler {
	return HandlerWithOptions(si, StdHTTPServerOptions{})
}

// ServeMux is an abstraction of http.ServeMux.
type ServeMux interface {
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

type StdHTTPServerOptions struct {
	BaseURL          string
	BaseRouter       ServeMux
	Middlewares      []MiddlewareFunc
	ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
func HandlerFromMux(si ServerInterface, m ServeMux) http.Handler {
	return HandlerWithOptions(si, StdHTTPServerOptions{
		BaseRouter: m,
	})
}

func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
	return HandlerWithOptions(si, StdHTTPServerOptions{
		BaseURL:    baseURL,
		BaseRouter: m,
	})
}

// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
	m := options.BaseRouter

	if m == nil {
		m = http.NewServeMux()
	}
	if options.ErrorHandlerFunc == nil {
		options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
			http.Error(w, err.Error(), http.StatusBadRequest)
		}
	}

	wrapper := ServerInterfaceWrapper{
		Handler:            si,
		HandlerMiddlewares: options.Middlewares,
		ErrorHandlerFunc:   options.ErrorHandlerFunc,
	}

	m.HandleFunc("POST "+options.BaseURL+"/api/v1/telegram/interactions/webhook", wrapper.PostTelegramInteractionWebhook)
	m.HandleFunc("POST "+options.BaseURL+"/v1/telegram/interaction-deliveries", wrapper.PostTelegramInteractionDelivery)

	return m
}

type PostTelegramInteractionWebhookRequestObject struct {
	Body *PostTelegramInteractionWebhookJSONRequestBody
}

type PostTelegramInteractionWebhookResponseObject interface {
	VisitPostTelegramInteractionWebhookResponse(w http.ResponseWriter) error
}

type PostTelegramInteractionWebhook204Response struct {
}

func (response PostTelegramInteractionWebhook204Response) VisitPostTelegramInteractionWebhookResponse(w http.ResponseWriter) error {
	w.WriteHeader(204)
	return nil
}

type PostTelegramInteractionWebhook400Response struct {
}

func (response PostTelegramInteractionWebhook400Response) VisitPostTelegramInteractionWebhookResponse(w http.ResponseWriter) error {
	w.WriteHeader(400)
	return nil
}

type PostTelegramInteractionWebhook401Response struct {
}

func (response PostTelegramInteractionWebhook401Response) VisitPostTelegramInteractionWebhookResponse(w http.ResponseWriter) error {
	w.WriteHeader(401)
	return nil
}

type PostTelegramInteractionWebhook503Response struct {
}

func (response PostTelegramInteractionWebhook503Response) VisitPostTelegramInteractionWebhookResponse(w http.ResponseWriter) error {
	w.WriteHeader(503)
	return nil
}

type PostTelegramInteractionDeliveryRequestObject struct {
	Body *PostTelegramInteractionDeliveryJSONRequestBody
}

type PostTelegramInteractionDeliveryResponseObject interface {
	VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error
}

type PostTelegramInteractionDelivery200JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery200JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(200)

	return json.NewEncoder(w).Encode(response)
}

type PostTelegramInteractionDelivery400JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery400JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(400)

	return json.NewEncoder(w).Encode(response)
}

type PostTelegramInteractionDelivery401JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery401JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(401)

	return json.NewEncoder(w).Encode(response)
}

type PostTelegramInteractionDelivery422JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery422JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(422)

	return json.NewEncoder(w).Encode(response)
}

type PostTelegramInteractionDelivery429JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery429JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(429)

	return json.NewEncoder(w).Encode(response)
}

type PostTelegramInteractionDelivery503JSONResponse TelegramInteractionDeliveryResponse

func (response PostTelegramInteractionDelivery503JSONResponse) VisitPostTelegramInteractionDeliveryResponse(w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(503)

	return json.NewEncoder(w).Encode(response)
}

// StrictServerInterface represents all server handlers.
type StrictServerInterface interface {
	// Receive one raw Telegram webhook update
	// (POST /api/v1/telegram/interactions/webhook)
	PostTelegramInteractionWebhook(ctx context.Context, request PostTelegramInteractionWebhookRequestObject) (PostTelegramInteractionWebhookResponseObject, error)
	// Accept one Telegram interaction delivery envelope from worker
	// (POST /v1/telegram/interaction-deliveries)
	PostTelegramInteractionDelivery(ctx context.Context, request PostTelegramInteractionDeliveryRequestObject) (PostTelegramInteractionDeliveryResponseObject, error)
}

type StrictHandlerFunc = strictnethttp.StrictHTTPHandlerFunc
type StrictMiddlewareFunc = strictnethttp.StrictHTTPMiddlewareFunc

type StrictHTTPServerOptions struct {
	RequestErrorHandlerFunc  func(w http.ResponseWriter, r *http.Request, err error)
	ResponseErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
}

func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
	return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictHTTPServerOptions{
		RequestErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
			http.Error(w, err.Error(), http.StatusBadRequest)
		},
		ResponseErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
			http.Error(w, err.Error(), http.StatusInternalServerError)
		},
	}}
}

func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictHTTPServerOptions) ServerInterface {
	return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
}

type strictHandler struct {
	ssi         StrictServerInterface
	middlewares []StrictMiddlewareFunc
	options     StrictHTTPServerOptions
}

// PostTelegramInteractionWebhook operation middleware
func (sh *strictHandler) PostTelegramInteractionWebhook(w http.ResponseWriter, r *http.Request) {
	var request PostTelegramInteractionWebhookRequestObject

	var body PostTelegramInteractionWebhookJSONRequestBody
	if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
		sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
		return
	}
	request.Body = &body

	handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
		return sh.ssi.PostTelegramInteractionWebhook(ctx, request.(PostTelegramInteractionWebhookRequestObject))
	}
	for _, middleware := range sh.middlewares {
		handler = middleware(handler, "PostTelegramInteractionWebhook")
	}

	response, err := handler(r.Context(), w, r, request)

	if err != nil {
		sh.options.ResponseErrorHandlerFunc(w, r, err)
	} else if validResponse, ok := response.(PostTelegramInteractionWebhookResponseObject); ok {
		if err := validResponse.VisitPostTelegramInteractionWebhookResponse(w); err != nil {
			sh.options.ResponseErrorHandlerFunc(w, r, err)
		}
	} else if response != nil {
		sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
	}
}

// PostTelegramInteractionDelivery operation middleware
func (sh *strictHandler) PostTelegramInteractionDelivery(w http.ResponseWriter, r *http.Request) {
	var request PostTelegramInteractionDeliveryRequestObject

	var body PostTelegramInteractionDeliveryJSONRequestBody
	if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
		sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
		return
	}
	request.Body = &body

	handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
		return sh.ssi.PostTelegramInteractionDelivery(ctx, request.(PostTelegramInteractionDeliveryRequestObject))
	}
	for _, middleware := range sh.middlewares {
		handler = middleware(handler, "PostTelegramInteractionDelivery")
	}

	response, err := handler(r.Context(), w, r, request)

	if err != nil {
		sh.options.ResponseErrorHandlerFunc(w, r, err)
	} else if validResponse, ok := response.(PostTelegramInteractionDeliveryResponseObject); ok {
		if err := validResponse.VisitPostTelegramInteractionDeliveryResponse(w); err != nil {
			sh.options.ResponseErrorHandlerFunc(w, r, err)
		}
	} else if response != nil {
		sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("unexpected response type: %T", response))
	}
}
