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


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

    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    expression: str | None = Field(
        None, alias="expression", serialization_alias="expression"
    )
    language: str | None = Field(None, alias="language", serialization_alias="language")


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

    applicability: PyList[ChargeItemDefinitionApplicability] | None = Field(
        None, alias="applicability", serialization_alias="applicability"
    )
    price_component: PyList[ChargeItemDefinitionPropertyGroupPriceComponent] | None = (
        Field(None, alias="priceComponent", serialization_alias="priceComponent")
    )


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

    amount: Money | None = Field(None, alias="amount", serialization_alias="amount")
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    factor: float | None = Field(None, alias="factor", serialization_alias="factor")
    type: Literal[
        "base", "surcharge", "deduction", "discount", "tax", "informational"
    ] = Field(alias="type", serialization_alias="type")


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

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

    applicability: PyList[ChargeItemDefinitionApplicability] | None = Field(
        None, alias="applicability", serialization_alias="applicability"
    )
    approval_date: str | None = Field(
        None, alias="approvalDate", serialization_alias="approvalDate"
    )
    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    date: str | None = Field(None, alias="date", serialization_alias="date")
    derived_from_uri: PyList[str] | None = Field(
        None, alias="derivedFromUri", serialization_alias="derivedFromUri"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    effective_period: Period | None = Field(
        None, alias="effectivePeriod", serialization_alias="effectivePeriod"
    )
    experimental: bool | None = Field(
        None, alias="experimental", serialization_alias="experimental"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    instance: PyList[Reference] | None = Field(
        None, alias="instance", serialization_alias="instance"
    )
    jurisdiction: PyList[CodeableConcept] | None = Field(
        None, alias="jurisdiction", serialization_alias="jurisdiction"
    )
    last_review_date: str | None = Field(
        None, alias="lastReviewDate", serialization_alias="lastReviewDate"
    )
    part_of: PyList[str] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    property_group: PyList[ChargeItemDefinitionPropertyGroup] | None = Field(
        None, alias="propertyGroup", serialization_alias="propertyGroup"
    )
    publisher: str | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    replaces: PyList[str] | None = Field(
        None, alias="replaces", serialization_alias="replaces"
    )
    status: Literal["draft", "active", "retired", "unknown"] = Field(
        alias="status", serialization_alias="status"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    url: str = Field(alias="url", serialization_alias="url")
    use_context: PyList[UsageContext] | None = Field(
        None, alias="useContext", serialization_alias="useContext"
    )
    version: 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) -> ChargeItemDefinition:
        return cls.model_validate_json(json)
