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


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

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


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

    category: CodeableConcept | None = Field(
        None, alias="category", serialization_alias="category"
    )
    detail: PyList[Reference] | None = Field(
        None, alias="detail", serialization_alias="detail"
    )
    diagnosis: PyList[CoverageEligibilityRequestItemDiagnosis] | None = Field(
        None, alias="diagnosis", serialization_alias="diagnosis"
    )
    facility: Reference | None = Field(
        None, alias="facility", serialization_alias="facility"
    )
    modifier: PyList[CodeableConcept] | None = Field(
        None, alias="modifier", serialization_alias="modifier"
    )
    product_or_service: CodeableConcept | None = Field(
        None, alias="productOrService", serialization_alias="productOrService"
    )
    provider: Reference | None = Field(
        None, alias="provider", serialization_alias="provider"
    )
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    supporting_info_sequence: PyList[PositiveInt] | None = Field(
        None,
        alias="supportingInfoSequence",
        serialization_alias="supportingInfoSequence",
    )
    unit_price: Money | None = Field(
        None, alias="unitPrice", serialization_alias="unitPrice"
    )


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

    diagnosis_codeable_concept: CodeableConcept | None = Field(
        None,
        alias="diagnosisCodeableConcept",
        serialization_alias="diagnosisCodeableConcept",
    )
    diagnosis_reference: Reference | None = Field(
        None, alias="diagnosisReference", serialization_alias="diagnosisReference"
    )


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

    applies_to_all: bool | None = Field(
        None, alias="appliesToAll", serialization_alias="appliesToAll"
    )
    information: Reference = Field(
        alias="information", serialization_alias="information"
    )
    sequence: PositiveInt = Field(alias="sequence", serialization_alias="sequence")


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

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

    created: str = Field(alias="created", serialization_alias="created")
    enterer: Reference | None = Field(
        None, alias="enterer", serialization_alias="enterer"
    )
    facility: Reference | None = Field(
        None, alias="facility", serialization_alias="facility"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    insurance: PyList[CoverageEligibilityRequestInsurance] | None = Field(
        None, alias="insurance", serialization_alias="insurance"
    )
    insurer: Reference = Field(alias="insurer", serialization_alias="insurer")
    item: PyList[CoverageEligibilityRequestItem] | None = Field(
        None, alias="item", serialization_alias="item"
    )
    patient: Reference = Field(alias="patient", serialization_alias="patient")
    priority: CodeableConcept | None = Field(
        None, alias="priority", serialization_alias="priority"
    )
    provider: Reference | None = Field(
        None, alias="provider", serialization_alias="provider"
    )
    purpose: PyList[
        Literal["auth-requirements", "benefits", "discovery", "validation"]
    ] = Field(alias="purpose", serialization_alias="purpose")
    serviced_date: str | None = Field(
        None, alias="servicedDate", serialization_alias="servicedDate"
    )
    serviced_period: Period | None = Field(
        None, alias="servicedPeriod", serialization_alias="servicedPeriod"
    )
    status: Literal["active", "cancelled", "draft", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )
    supporting_info: PyList[CoverageEligibilityRequestSupportingInfo] | None = Field(
        None, alias="supportingInfo", serialization_alias="supportingInfo"
    )

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