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


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

    description: PyList[CodeableConcept] | None = Field(
        None, alias="description", serialization_alias="description"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    name: str = Field(alias="name", serialization_alias="name")
    type: Literal[
        "udi-label-name",
        "user-friendly-name",
        "patient-reported-name",
        "manufacturer-name",
        "model-name",
        "other",
    ] = Field(alias="type", serialization_alias="type")


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

    allergenic_indicator: bool | None = Field(
        None, alias="allergenicIndicator", serialization_alias="allergenicIndicator"
    )
    alternate: bool | None = Field(
        None, alias="alternate", serialization_alias="alternate"
    )
    substance: CodeableConcept = Field(
        alias="substance", serialization_alias="substance"
    )


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

    type: CodeableConcept = Field(alias="type", serialization_alias="type")
    value_code: PyList[CodeableConcept] | None = Field(
        None, alias="valueCode", serialization_alias="valueCode"
    )
    value_quantity: PyList[Quantity] | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )


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

    system_type: str = Field(alias="systemType", serialization_alias="systemType")
    version: str | None = Field(None, alias="version", serialization_alias="version")


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

    device_identifier: str = Field(
        alias="deviceIdentifier", serialization_alias="deviceIdentifier"
    )
    issuer: str = Field(alias="issuer", serialization_alias="issuer")
    jurisdiction: str = Field(alias="jurisdiction", serialization_alias="jurisdiction")


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

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

    capability: PyList[DeviceDefinitionCapability] | None = Field(
        None, alias="capability", serialization_alias="capability"
    )
    contact: PyList[ContactPoint] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    device_name: PyList[DeviceDefinitionDeviceName] | None = Field(
        None, alias="deviceName", serialization_alias="deviceName"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    language_code: PyList[CodeableConcept] | None = Field(
        None, alias="languageCode", serialization_alias="languageCode"
    )
    manufacturer_reference: Reference | None = Field(
        None, alias="manufacturerReference", serialization_alias="manufacturerReference"
    )
    manufacturer_string: str | None = Field(
        None, alias="manufacturerString", serialization_alias="manufacturerString"
    )
    material: PyList[DeviceDefinitionMaterial] | None = Field(
        None, alias="material", serialization_alias="material"
    )
    model_number: str | None = Field(
        None, alias="modelNumber", serialization_alias="modelNumber"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    online_information: str | None = Field(
        None, alias="onlineInformation", serialization_alias="onlineInformation"
    )
    owner: Reference | None = Field(None, alias="owner", serialization_alias="owner")
    parent_device: Reference | None = Field(
        None, alias="parentDevice", serialization_alias="parentDevice"
    )
    physical_characteristics: ProdCharacteristic | None = Field(
        None,
        alias="physicalCharacteristics",
        serialization_alias="physicalCharacteristics",
    )
    property: PyList[DeviceDefinitionProperty] | None = Field(
        None, alias="property", serialization_alias="property"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    safety: PyList[CodeableConcept] | None = Field(
        None, alias="safety", serialization_alias="safety"
    )
    shelf_life_storage: PyList[ProductShelfLife] | None = Field(
        None, alias="shelfLifeStorage", serialization_alias="shelfLifeStorage"
    )
    specialization: PyList[DeviceDefinitionSpecialization] | None = Field(
        None, alias="specialization", serialization_alias="specialization"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    udi_device_identifier: PyList[DeviceDefinitionUdiDeviceIdentifier] | None = Field(
        None, alias="udiDeviceIdentifier", serialization_alias="udiDeviceIdentifier"
    )
    url: str | None = Field(None, alias="url", serialization_alias="url")
    version: PyList[str] | None = Field(
        None, alias="version", serialization_alias="version"
    )

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