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


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

    add: float | None = Field(None, alias="add", serialization_alias="add")
    axis: int | None = Field(None, alias="axis", serialization_alias="axis")
    back_curve: float | None = Field(
        None, alias="backCurve", serialization_alias="backCurve"
    )
    brand: str | None = Field(None, alias="brand", serialization_alias="brand")
    color: str | None = Field(None, alias="color", serialization_alias="color")
    cylinder: float | None = Field(
        None, alias="cylinder", serialization_alias="cylinder"
    )
    diameter: float | None = Field(
        None, alias="diameter", serialization_alias="diameter"
    )
    duration: Quantity | None = Field(
        None, alias="duration", serialization_alias="duration"
    )
    eye: Literal["right", "left"] = Field(alias="eye", serialization_alias="eye")
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    power: float | None = Field(None, alias="power", serialization_alias="power")
    prism: PyList[VisionPrescriptionLensSpecificationPrism] | None = Field(
        None, alias="prism", serialization_alias="prism"
    )
    product: CodeableConcept = Field(alias="product", serialization_alias="product")
    sphere: float | None = Field(None, alias="sphere", serialization_alias="sphere")


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

    amount: float = Field(alias="amount", serialization_alias="amount")
    base: Literal["up", "down", "in", "out"] = Field(
        alias="base", serialization_alias="base"
    )


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

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

    created: str = Field(alias="created", serialization_alias="created")
    date_written: str = Field(alias="dateWritten", serialization_alias="dateWritten")
    encounter: Reference | None = Field(
        None, alias="encounter", serialization_alias="encounter"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    lens_specification: PyList[VisionPrescriptionLensSpecification] = Field(
        alias="lensSpecification", serialization_alias="lensSpecification"
    )
    patient: Reference = Field(alias="patient", serialization_alias="patient")
    prescriber: Reference = Field(alias="prescriber", serialization_alias="prescriber")
    status: Literal["active", "cancelled", "draft", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )

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