# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
import typing_extensions
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from ...core.serialization import FieldMetadata
from .code_response import CodeResponse


class UploadRequestJson(UniversalBaseModel):
    """
    Upload codes in JSON format. Either 'file' or 'codes' must be provided.
    If both are provided, 'codes' takes precedence.
    """

    name: str = pydantic.Field()
    """
    Name of the code system. Names are case-insensitive and stored uppercase.
    Builtin system names (e.g. ICD-10-CM, SNOMED_CT_US_LITE, LOINC, CPT, etc.) are
    reserved and cannot be used for custom uploads; attempts return HTTP 403 Forbidden.
    """

    version: str = pydantic.Field()
    """
    Version of the code system
    """

    revision: typing.Optional[float] = pydantic.Field(default=None)
    """
    Optional revision number
    """

    file: typing.Optional[str] = pydantic.Field(default=None)
    """
    The file contents as a base64-encoded JSON array string.
    Prefer using 'codes' instead to pass the array directly without base64 encoding.
    """

    codes: typing.Optional[typing.List[CodeResponse]] = pydantic.Field(default=None)
    """
    The codes to upload as a JSON array.
    This is the preferred way to upload JSON codes, as it avoids unnecessary base64 encoding.
    If both 'codes' and 'file' are provided, 'codes' takes precedence.
    """

    replace: typing.Optional[bool] = pydantic.Field(default=None)
    """
    If true, replaces an existing code system with the same name and version.
    Builtin systems cannot be replaced; attempts to do so return HTTP 403 Forbidden.
    When false (default), uploading a duplicate returns 409 Conflict.
    """

    async_: typing_extensions.Annotated[typing.Optional[bool], FieldMetadata(alias="async")] = pydantic.Field(
        default=None
    )
    """
    If true, returns 202 Accepted immediately after validation and starts processing
    in the background. Poll GET /construe/codes/systems/{name}?version={version} to
    check when status transitions from "processing" to "ready" or "failed".
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
