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


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

    state: (
        Literal["not-calibrated", "calibration-required", "calibrated", "unspecified"]
        | None
    ) = Field(None, alias="state", serialization_alias="state")
    time: str | None = Field(None, alias="time", serialization_alias="time")
    type: Literal["unspecified", "offset", "gain", "two-point"] | None = Field(
        None, alias="type", serialization_alias="type"
    )


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

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

    calibration: PyList[DeviceMetricCalibration] | None = Field(
        None, alias="calibration", serialization_alias="calibration"
    )
    category: Literal["measurement", "setting", "calculation", "unspecified"] = Field(
        alias="category", serialization_alias="category"
    )
    color: (
        Literal["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"]
        | None
    ) = Field(None, alias="color", serialization_alias="color")
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    measurement_period: Timing | None = Field(
        None, alias="measurementPeriod", serialization_alias="measurementPeriod"
    )
    operational_status: Literal["on", "off", "standby", "entered-in-error"] | None = (
        Field(None, alias="operationalStatus", serialization_alias="operationalStatus")
    )
    parent: Reference | None = Field(None, alias="parent", serialization_alias="parent")
    source: Reference | None = Field(None, alias="source", serialization_alias="source")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")
    unit: CodeableConcept | None = Field(None, alias="unit", serialization_alias="unit")

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