# 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 (
    Address,
    Attachment,
    BackboneElement,
    ContactPoint,
    HumanName,
    Identifier,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    assurance: Literal["level1", "level2", "level3", "level4"] | None = Field(
        None, alias="assurance", serialization_alias="assurance"
    )
    target: Reference = Field(alias="target", serialization_alias="target")


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

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

    active: bool | None = Field(None, alias="active", serialization_alias="active")
    address: PyList[Address] | None = Field(
        None, alias="address", serialization_alias="address"
    )
    birth_date: str | None = Field(
        None, alias="birthDate", serialization_alias="birthDate"
    )
    gender: Literal["male", "female", "other", "unknown"] | None = Field(
        None, alias="gender", serialization_alias="gender"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    link: PyList[PersonLink] | None = Field(
        None, alias="link", serialization_alias="link"
    )
    managing_organization: Reference | None = Field(
        None, alias="managingOrganization", serialization_alias="managingOrganization"
    )
    name: PyList[HumanName] | None = Field(
        None, alias="name", serialization_alias="name"
    )
    photo: Attachment | None = Field(None, alias="photo", serialization_alias="photo")
    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) -> Person:
        return cls.model_validate_json(json)
