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


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    exclude: bool = Field(alias="exclude", serialization_alias="exclude")
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_codeable_concept: CodeableConcept | None = Field(
        None, alias="valueCodeableConcept", serialization_alias="valueCodeableConcept"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_range: Range | None = Field(
        None, alias="valueRange", serialization_alias="valueRange"
    )
    value_reference: Reference | None = Field(
        None, alias="valueReference", serialization_alias="valueReference"
    )


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

    entity: Reference = Field(alias="entity", serialization_alias="entity")
    inactive: bool | None = Field(
        None, alias="inactive", serialization_alias="inactive"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")


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

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

    active: bool | None = Field(None, alias="active", serialization_alias="active")
    actual: bool = Field(alias="actual", serialization_alias="actual")
    characteristic: PyList[GroupCharacteristic] | None = Field(
        None, alias="characteristic", serialization_alias="characteristic"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    managing_entity: Reference | None = Field(
        None, alias="managingEntity", serialization_alias="managingEntity"
    )
    member: PyList[GroupMember] | None = Field(
        None, alias="member", serialization_alias="member"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    quantity: int | None = Field(None, alias="quantity", serialization_alias="quantity")
    type: Literal[
        "person", "animal", "practitioner", "device", "medication", "substance"
    ] = Field(alias="type", serialization_alias="type")

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