# 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, Reference
from fhirschemapy.R4B.domain_resource import DomainResource


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

    resource: Reference = Field(alias="resource", serialization_alias="resource")
    type: Literal["source", "alternate", "historical"] = Field(
        alias="type", serialization_alias="type"
    )


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

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

    active: bool | None = Field(None, alias="active", serialization_alias="active")
    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    item: PyList[LinkageItem] = Field(alias="item", serialization_alias="item")

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