# WARNING: This file is autogenerated by FHIR Schema Codegen.
# https://github.com/fhir-schema/fhir-schema-codegen
# Any manual changes made to this file may be overwritten.

from __future__ import annotations
from pydantic import ConfigDict, Field
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Attachment,
    BackboneElement,
    Coding,
    Identifier,
    Quantity,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


class QuestionnaireResponseItem(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    answer: PyList[QuestionnaireResponseItemAnswer] | None = Field(
        None, alias="answer", serialization_alias="answer"
    )
    definition: str | None = Field(
        None, alias="definition", serialization_alias="definition"
    )
    item: PyList[QuestionnaireResponseItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    link_id: str = Field(alias="linkId", serialization_alias="linkId")
    text: str | None = Field(None, alias="text", serialization_alias="text")


class QuestionnaireResponseItemAnswer(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    item: PyList[QuestionnaireResponseItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    value_attachment: Attachment | None = Field(
        None, alias="valueAttachment", serialization_alias="valueAttachment"
    )
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_coding: Coding | None = Field(
        None, alias="valueCoding", serialization_alias="valueCoding"
    )
    value_date: str | None = Field(
        None, alias="valueDate", serialization_alias="valueDate"
    )
    value_date_time: str | None = Field(
        None, alias="valueDateTime", serialization_alias="valueDateTime"
    )
    value_decimal: float | None = Field(
        None, alias="valueDecimal", serialization_alias="valueDecimal"
    )
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_reference: Reference | None = Field(
        None, alias="valueReference", serialization_alias="valueReference"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )
    value_time: str | None = Field(
        None, alias="valueTime", serialization_alias="valueTime"
    )
    value_uri: str | None = Field(
        None, alias="valueUri", serialization_alias="valueUri"
    )


class QuestionnaireResponse(DomainResource):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    resource_type: str = Field(
        default="QuestionnaireResponse",
        alias="resourceType",
        serialization_alias="resourceType",
        frozen=True,
        pattern="QuestionnaireResponse",
    )

    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    authored: str | None = Field(None, alias="authored", serialization_alias="authored")
    based_on: PyList[Reference] | None = Field(
        None, alias="basedOn", serialization_alias="basedOn"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    item: PyList[QuestionnaireResponseItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    questionnaire: str | None = Field(
        None, alias="questionnaire", serialization_alias="questionnaire"
    )
    source: Reference | None = Field(None, alias="source", serialization_alias="source")
    status: Literal[
        "in-progress", "completed", "amended", "entered-in-error", "stopped"
    ] = Field(alias="status", serialization_alias="status")
    subject: Reference | None = Field(
        None, alias="subject", serialization_alias="subject"
    )

    def to_json(self, indent: int | None = None) -> str:
        return self.model_dump_json(
            exclude_unset=True, exclude_none=True, indent=indent
        )

    @classmethod
    def from_json(cls, json: str) -> QuestionnaireResponse:
        return cls.model_validate_json(json)
