# 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, PositiveInt
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Address,
    Attachment,
    BackboneElement,
    CodeableConcept,
    Identifier,
    Money,
    Period,
    Quantity,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    adjudication: PyList[ClaimResponseItemAdjudication] = Field(
        alias="adjudication", serialization_alias="adjudication"
    )
    body_site: CodeableConcept | None = Field(
        None, alias="bodySite", serialization_alias="bodySite"
    )
    detail: PyList[ClaimResponseAddItemDetail] | None = Field(
        None, alias="detail", serialization_alias="detail"
    )
    detail_sequence: PyList[PositiveInt] | None = Field(
        None, alias="detailSequence", serialization_alias="detailSequence"
    )
    factor: float | None = Field(None, alias="factor", serialization_alias="factor")
    item_sequence: PyList[PositiveInt] | None = Field(
        None, alias="itemSequence", serialization_alias="itemSequence"
    )
    location_address: Address | None = Field(
        None, alias="locationAddress", serialization_alias="locationAddress"
    )
    location_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="locationCodeableConcept",
        serialization_alias="locationCodeableConcept",
    )
    location_reference: Reference | None = Field(
        None, alias="locationReference", serialization_alias="locationReference"
    )
    modifier: PyList[CodeableConcept] | None = Field(
        None, alias="modifier", serialization_alias="modifier"
    )
    net: Money | None = Field(None, alias="net", serialization_alias="net")
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )
    product_or_service: CodeableConcept = Field(
        alias="productOrService", serialization_alias="productOrService"
    )
    program_code: PyList[CodeableConcept] | None = Field(
        None, alias="programCode", serialization_alias="programCode"
    )
    provider: PyList[Reference] | None = Field(
        None, alias="provider", serialization_alias="provider"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    serviced_date: str | None = Field(
        None, alias="servicedDate", serialization_alias="servicedDate"
    )
    serviced_period: Period | None = Field(
        None, alias="servicedPeriod", serialization_alias="servicedPeriod"
    )
    subdetail_sequence: PyList[PositiveInt] | None = Field(
        None, alias="subdetailSequence", serialization_alias="subdetailSequence"
    )
    sub_site: PyList[CodeableConcept] | None = Field(
        None, alias="subSite", serialization_alias="subSite"
    )
    unit_price: Money | None = Field(
        None, alias="unitPrice", serialization_alias="unitPrice"
    )


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

    adjudication: PyList[ClaimResponseItemAdjudication] = Field(
        alias="adjudication", serialization_alias="adjudication"
    )
    factor: float | None = Field(None, alias="factor", serialization_alias="factor")
    modifier: PyList[CodeableConcept] | None = Field(
        None, alias="modifier", serialization_alias="modifier"
    )
    net: Money | None = Field(None, alias="net", serialization_alias="net")
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )
    product_or_service: CodeableConcept = Field(
        alias="productOrService", serialization_alias="productOrService"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    sub_detail: PyList[ClaimResponseAddItemDetailSubDetail] | None = Field(
        None, alias="subDetail", serialization_alias="subDetail"
    )
    unit_price: Money | None = Field(
        None, alias="unitPrice", serialization_alias="unitPrice"
    )


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

    adjudication: PyList[ClaimResponseItemAdjudication] = Field(
        alias="adjudication", serialization_alias="adjudication"
    )
    factor: float | None = Field(None, alias="factor", serialization_alias="factor")
    modifier: PyList[CodeableConcept] | None = Field(
        None, alias="modifier", serialization_alias="modifier"
    )
    net: Money | None = Field(None, alias="net", serialization_alias="net")
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )
    product_or_service: CodeableConcept = Field(
        alias="productOrService", serialization_alias="productOrService"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    unit_price: Money | None = Field(
        None, alias="unitPrice", serialization_alias="unitPrice"
    )


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

    code: CodeableConcept = Field(alias="code", serialization_alias="code")
    detail_sequence: PositiveInt | None = Field(
        None, alias="detailSequence", serialization_alias="detailSequence"
    )
    item_sequence: PositiveInt | None = Field(
        None, alias="itemSequence", serialization_alias="itemSequence"
    )
    sub_detail_sequence: PositiveInt | None = Field(
        None, alias="subDetailSequence", serialization_alias="subDetailSequence"
    )


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

    business_arrangement: str | None = Field(
        None, alias="businessArrangement", serialization_alias="businessArrangement"
    )
    claim_response: Reference | None = Field(
        None, alias="claimResponse", serialization_alias="claimResponse"
    )
    coverage: Reference = Field(alias="coverage", serialization_alias="coverage")
    focal: bool = Field(alias="focal", serialization_alias="focal")
    sequence: PositiveInt = Field(alias="sequence", serialization_alias="sequence")


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

    adjudication: PyList[ClaimResponseItemAdjudication] = Field(
        alias="adjudication", serialization_alias="adjudication"
    )
    detail: PyList[ClaimResponseItemDetail] | None = Field(
        None, alias="detail", serialization_alias="detail"
    )
    item_sequence: PositiveInt = Field(
        alias="itemSequence", serialization_alias="itemSequence"
    )
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )


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

    amount: Money | None = Field(None, alias="amount", serialization_alias="amount")
    category: CodeableConcept = Field(alias="category", serialization_alias="category")
    reason: CodeableConcept | None = Field(
        None, alias="reason", serialization_alias="reason"
    )
    value: float | None = Field(None, alias="value", serialization_alias="value")


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

    adjudication: PyList[ClaimResponseItemAdjudication] = Field(
        alias="adjudication", serialization_alias="adjudication"
    )
    detail_sequence: PositiveInt = Field(
        alias="detailSequence", serialization_alias="detailSequence"
    )
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )
    sub_detail: PyList[ClaimResponseItemDetailSubDetail] | None = Field(
        None, alias="subDetail", serialization_alias="subDetail"
    )


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

    adjudication: PyList[ClaimResponseItemAdjudication] | None = Field(
        None, alias="adjudication", serialization_alias="adjudication"
    )
    note_number: PyList[PositiveInt] | None = Field(
        None, alias="noteNumber", serialization_alias="noteNumber"
    )
    sub_detail_sequence: PositiveInt = Field(
        alias="subDetailSequence", serialization_alias="subDetailSequence"
    )


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

    adjustment: Money | None = Field(
        None, alias="adjustment", serialization_alias="adjustment"
    )
    adjustment_reason: CodeableConcept | None = Field(
        None, alias="adjustmentReason", serialization_alias="adjustmentReason"
    )
    amount: Money = Field(alias="amount", serialization_alias="amount")
    date: str | None = Field(None, alias="date", serialization_alias="date")
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    language: CodeableConcept | None = Field(
        None, alias="language", serialization_alias="language"
    )
    number: PositiveInt | None = Field(
        None, alias="number", serialization_alias="number"
    )
    text: str = Field(alias="text", serialization_alias="text")
    type: Literal["display", "print", "printoper"] | None = Field(
        None, alias="type", serialization_alias="type"
    )


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

    amount: Money = Field(alias="amount", serialization_alias="amount")
    category: CodeableConcept = Field(alias="category", serialization_alias="category")


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

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

    add_item: PyList[ClaimResponseAddItem] | None = Field(
        None, alias="addItem", serialization_alias="addItem"
    )
    adjudication: PyList[ClaimResponseItemAdjudication] | None = Field(
        None, alias="adjudication", serialization_alias="adjudication"
    )
    communication_request: PyList[Reference] | None = Field(
        None, alias="communicationRequest", serialization_alias="communicationRequest"
    )
    created: str = Field(alias="created", serialization_alias="created")
    disposition: str | None = Field(
        None, alias="disposition", serialization_alias="disposition"
    )
    error: PyList[ClaimResponseError] | None = Field(
        None, alias="error", serialization_alias="error"
    )
    form: Attachment | None = Field(None, alias="form", serialization_alias="form")
    form_code: CodeableConcept | None = Field(
        None, alias="formCode", serialization_alias="formCode"
    )
    funds_reserve: CodeableConcept | None = Field(
        None, alias="fundsReserve", serialization_alias="fundsReserve"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    insurance: PyList[ClaimResponseInsurance] | None = Field(
        None, alias="insurance", serialization_alias="insurance"
    )
    insurer: Reference = Field(alias="insurer", serialization_alias="insurer")
    item: PyList[ClaimResponseItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    outcome: Literal["queued", "complete", "error", "partial"] = Field(
        alias="outcome", serialization_alias="outcome"
    )
    patient: Reference = Field(alias="patient", serialization_alias="patient")
    payee_type: CodeableConcept | None = Field(
        None, alias="payeeType", serialization_alias="payeeType"
    )
    payment: ClaimResponsePayment | None = Field(
        None, alias="payment", serialization_alias="payment"
    )
    pre_auth_period: Period | None = Field(
        None, alias="preAuthPeriod", serialization_alias="preAuthPeriod"
    )
    pre_auth_ref: str | None = Field(
        None, alias="preAuthRef", serialization_alias="preAuthRef"
    )
    process_note: PyList[ClaimResponseProcessNote] | None = Field(
        None, alias="processNote", serialization_alias="processNote"
    )
    request: Reference | None = Field(
        None, alias="request", serialization_alias="request"
    )
    requestor: Reference | None = Field(
        None, alias="requestor", serialization_alias="requestor"
    )
    status: Literal["active", "cancelled", "draft", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )
    sub_type: CodeableConcept | None = Field(
        None, alias="subType", serialization_alias="subType"
    )
    total: PyList[ClaimResponseTotal] | None = Field(
        None, alias="total", serialization_alias="total"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")
    use: Literal["claim", "preauthorization", "predetermination"] = Field(
        alias="use", serialization_alias="use"
    )

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