# 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 CoverageClass(BackboneElement):
    model_config = ConfigDict(serialize_by_alias=True, extra="forbid")

    name: str | None = Field(None, alias="name", serialization_alias="name")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")
    value: str = Field(alias="value", serialization_alias="value")


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

    exception: PyList[CoverageCostToBeneficiaryException] | None = Field(
        None, alias="exception", serialization_alias="exception"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    value_money: Money | None = Field(
        None, alias="valueMoney", serialization_alias="valueMoney"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )


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

    period: Period | None = Field(None, alias="period", serialization_alias="period")
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

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

    beneficiary: Reference = Field(
        alias="beneficiary", serialization_alias="beneficiary"
    )
    class_: PyList[CoverageClass] | None = Field(
        None, alias="class", serialization_alias="class"
    )
    contract: PyList[Reference] | None = Field(
        None, alias="contract", serialization_alias="contract"
    )
    cost_to_beneficiary: PyList[CoverageCostToBeneficiary] | None = Field(
        None, alias="costToBeneficiary", serialization_alias="costToBeneficiary"
    )
    dependent: str | None = Field(
        None, alias="dependent", serialization_alias="dependent"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    network: str | None = Field(None, alias="network", serialization_alias="network")
    order: PositiveInt | None = Field(None, alias="order", serialization_alias="order")
    payor: PyList[Reference] = Field(alias="payor", serialization_alias="payor")
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    policy_holder: Reference | None = Field(
        None, alias="policyHolder", serialization_alias="policyHolder"
    )
    relationship: CodeableConcept | None = Field(
        None, alias="relationship", serialization_alias="relationship"
    )
    status: Literal["active", "cancelled", "draft", "entered-in-error"] = Field(
        alias="status", serialization_alias="status"
    )
    subrogation: bool | None = Field(
        None, alias="subrogation", serialization_alias="subrogation"
    )
    subscriber: Reference | None = Field(
        None, alias="subscriber", serialization_alias="subscriber"
    )
    subscriber_id: str | None = Field(
        None, alias="subscriberId", serialization_alias="subscriberId"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")

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