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


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

    actor: Reference = Field(alias="actor", serialization_alias="actor")
    function: CodeableConcept | None = Field(
        None, alias="function", serialization_alias="function"
    )


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

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

    account: PyList[Reference] | None = Field(
        None, alias="account", serialization_alias="account"
    )
    bodysite: PyList[CodeableConcept] | None = Field(
        None, alias="bodysite", serialization_alias="bodysite"
    )
    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    context: Reference | None = Field(
        None, alias="context", serialization_alias="context"
    )
    cost_center: Reference | None = Field(
        None, alias="costCenter", serialization_alias="costCenter"
    )
    definition_canonical: PyList[str] | None = Field(
        None, alias="definitionCanonical", serialization_alias="definitionCanonical"
    )
    definition_uri: PyList[str] | None = Field(
        None, alias="definitionUri", serialization_alias="definitionUri"
    )
    entered_date: str | None = Field(
        None, alias="enteredDate", serialization_alias="enteredDate"
    )
    enterer: Reference | None = Field(
        None, alias="enterer", serialization_alias="enterer"
    )
    factor_override: float | None = Field(
        None, alias="factorOverride", serialization_alias="factorOverride"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    occurrence_timing: Timing | None = Field(
        None, alias="occurrenceTiming", serialization_alias="occurrenceTiming"
    )
    override_reason: str | None = Field(
        None, alias="overrideReason", serialization_alias="overrideReason"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    performer: PyList[ChargeItemPerformer] | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    performing_organization: Reference | None = Field(
        None,
        alias="performingOrganization",
        serialization_alias="performingOrganization",
    )
    price_override: Money | None = Field(
        None, alias="priceOverride", serialization_alias="priceOverride"
    )
    product_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="productCodeableConcept",
        serialization_alias="productCodeableConcept",
    )
    product_reference: Reference | None = Field(
        None, alias="productReference", serialization_alias="productReference"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    reason: PyList[CodeableConcept] | None = Field(
        None, alias="reason", serialization_alias="reason"
    )
    requesting_organization: Reference | None = Field(
        None,
        alias="requestingOrganization",
        serialization_alias="requestingOrganization",
    )
    service: PyList[Reference] | None = Field(
        None, alias="service", serialization_alias="service"
    )
    status: Literal[
        "planned",
        "billable",
        "not-billable",
        "aborted",
        "billed",
        "entered-in-error",
        "unknown",
    ] = Field(alias="status", serialization_alias="status")
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    supporting_information: PyList[Reference] | None = Field(
        None, alias="supportingInformation", serialization_alias="supportingInformation"
    )

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