# Code generated by smithy-python-codegen DO NOT EDIT.

from typing import AsyncIterable
from urllib.parse import quote as urlquote

from smithy_core import URI as _URI
from smithy_core.aio.types import AsyncBytesReader, SeekableAsyncBytesReader
from smithy_core.types import TimestampFormat
from smithy_http import Field, Fields
from smithy_http.aio import HTTPRequest as _HTTPRequest
from smithy_http.aio.interfaces import HTTPRequest
from smithy_json import JSONCodec

from .config import Config
from .models import QueryAgentInput, ServiceError


async def _serialize_query_agent(input: QueryAgentInput, config: Config) -> HTTPRequest:
    if not input.experiment_id:
        raise ServiceError("experiment_id must not be empty.")

    path = "/agents/{experiment_id}/query".format(
        experiment_id=urlquote(input.experiment_id, safe=''),
    )
    query: str = f''

    body: AsyncIterable[bytes] = AsyncBytesReader(b'')
    codec = JSONCodec(default_timestamp_format=TimestampFormat.EPOCH_SECONDS)
    content = codec.serialize(input)
    if not content:
        content = b"{}"
    content_length = len(content)
    body = SeekableAsyncBytesReader(content)

    headers = Fields(
        [
            Field(name="Content-Type", values=["application/json"]),
            Field(name="Content-Length", values=[str(content_length)]),

        ]
    )

    return _HTTPRequest(
        destination=_URI(
            host="",
            path=path,
            scheme="https",
            query=query,
        ),
        method="POST",
        fields=headers,
        body=body,
    )
