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


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

    amount: Money | None = Field(None, 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"
    )
    payee: Reference | None = Field(None, alias="payee", serialization_alias="payee")
    predecessor: Identifier | None = Field(
        None, alias="predecessor", serialization_alias="predecessor"
    )
    request: Reference | None = Field(
        None, alias="request", serialization_alias="request"
    )
    response: Reference | None = Field(
        None, alias="response", serialization_alias="response"
    )
    responsible: Reference | None = Field(
        None, alias="responsible", serialization_alias="responsible"
    )
    submitter: Reference | None = Field(
        None, alias="submitter", serialization_alias="submitter"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

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


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

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

    created: str = Field(alias="created", serialization_alias="created")
    detail: PyList[PaymentReconciliationDetail] | None = Field(
        None, alias="detail", serialization_alias="detail"
    )
    disposition: str | None = Field(
        None, alias="disposition", serialization_alias="disposition"
    )
    form_code: CodeableConcept | None = Field(
        None, alias="formCode", serialization_alias="formCode"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    outcome: Literal["queued", "complete", "error", "partial"] | None = Field(
        None, alias="outcome", serialization_alias="outcome"
    )
    payment_amount: Money = Field(
        alias="paymentAmount", serialization_alias="paymentAmount"
    )
    payment_date: str = Field(alias="paymentDate", serialization_alias="paymentDate")
    payment_identifier: Identifier | None = Field(
        None, alias="paymentIdentifier", serialization_alias="paymentIdentifier"
    )
    payment_issuer: Reference | None = Field(
        None, alias="paymentIssuer", serialization_alias="paymentIssuer"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    process_note: PyList[PaymentReconciliationProcessNote] | 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"
    )

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