# 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 (
    Annotation,
    BackboneElement,
    CodeableConcept,
    ContactPoint,
    Identifier,
    Period,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    member: Reference | None = Field(None, alias="member", serialization_alias="member")
    on_behalf_of: Reference | None = Field(
        None, alias="onBehalfOf", serialization_alias="onBehalfOf"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    role: PyList[CodeableConcept] | None = Field(
        None, alias="role", serialization_alias="role"
    )


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

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

    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    managing_organization: PyList[Reference] | None = Field(
        None, alias="managingOrganization", serialization_alias="managingOrganization"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    participant: PyList[CareTeamParticipant] | None = Field(
        None, alias="participant", serialization_alias="participant"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    status: (
        Literal["proposed", "active", "suspended", "inactive", "entered-in-error"]
        | None
    ) = Field(None, alias="status", serialization_alias="status")
    subject: Reference | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    telecom: PyList[ContactPoint] | None = Field(
        None, alias="telecom", serialization_alias="telecom"
    )

    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) -> CareTeam:
        return cls.model_validate_json(json)
