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

import typing

import pydantic
from ...core.pydantic_utilities import IS_PYDANTIC_V2, UniversalBaseModel
from .citation import Citation


class ExtractedCodeResult(UniversalBaseModel):
    code: str = pydantic.Field()
    """
    The extracted code
    """

    description: str = pydantic.Field()
    """
    Short description of the code
    """

    valid: bool = pydantic.Field()
    """
    Whether the code passed validation. Always true unless include_invalid is set to true, in which case invalid codes will have this set to false.
    """

    reason: typing.Optional[str] = pydantic.Field(default=None)
    """
    Explanation for why this code was extracted (if include_rationale is true)
    """

    is_ancestor: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether this code is an ancestor (parent) of an extracted code rather than directly extracted.
    Only present when include_ancestors is true.
    """

    citations: typing.Optional[typing.List[Citation]] = pydantic.Field(default=None)
    """
    Source text references showing where this code was found in the input.
    Only present when include_citations is true and chunking method supports it.
    Ancestor codes do not receive citations.
    """

    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
