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


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

    address: Address | None = Field(
        None, alias="address", serialization_alias="address"
    )
    name: HumanName | None = Field(None, alias="name", serialization_alias="name")
    purpose: CodeableConcept | None = Field(
        None, alias="purpose", serialization_alias="purpose"
    )
    telecom: PyList[ContactPoint] | None = Field(
        None, alias="telecom", serialization_alias="telecom"
    )


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

    benefit: PyList[InsurancePlanCoverageBenefit] = Field(
        alias="benefit", serialization_alias="benefit"
    )
    network: PyList[Reference] | None = Field(
        None, alias="network", serialization_alias="network"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    limit: PyList[InsurancePlanCoverageBenefitLimit] | None = Field(
        None, alias="limit", serialization_alias="limit"
    )
    requirement: str | None = Field(
        None, alias="requirement", serialization_alias="requirement"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    code: CodeableConcept | None = Field(None, alias="code", serialization_alias="code")
    value: Quantity | None = Field(None, alias="value", serialization_alias="value")


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

    coverage_area: PyList[Reference] | None = Field(
        None, alias="coverageArea", serialization_alias="coverageArea"
    )
    general_cost: PyList[InsurancePlanPlanGeneralCost] | None = Field(
        None, alias="generalCost", serialization_alias="generalCost"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    network: PyList[Reference] | None = Field(
        None, alias="network", serialization_alias="network"
    )
    specific_cost: PyList[InsurancePlanPlanSpecificCost] | None = Field(
        None, alias="specificCost", serialization_alias="specificCost"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    comment: str | None = Field(None, alias="comment", serialization_alias="comment")
    cost: Money | None = Field(None, alias="cost", serialization_alias="cost")
    group_size: PositiveInt | None = Field(
        None, alias="groupSize", serialization_alias="groupSize"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    benefit: PyList[InsurancePlanPlanSpecificCostBenefit] | None = Field(
        None, alias="benefit", serialization_alias="benefit"
    )
    category: CodeableConcept = Field(alias="category", serialization_alias="category")


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

    cost: PyList[InsurancePlanPlanSpecificCostBenefitCost] | None = Field(
        None, alias="cost", serialization_alias="cost"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    applicability: CodeableConcept | None = Field(
        None, alias="applicability", serialization_alias="applicability"
    )
    qualifiers: PyList[CodeableConcept] | None = Field(
        None, alias="qualifiers", serialization_alias="qualifiers"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")
    value: Quantity | None = Field(None, alias="value", serialization_alias="value")


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

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

    administered_by: Reference | None = Field(
        None, alias="administeredBy", serialization_alias="administeredBy"
    )
    alias: PyList[str] | None = Field(None, alias="alias", serialization_alias="alias")
    contact: PyList[InsurancePlanContact] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    coverage: PyList[InsurancePlanCoverage] | None = Field(
        None, alias="coverage", serialization_alias="coverage"
    )
    coverage_area: PyList[Reference] | None = Field(
        None, alias="coverageArea", serialization_alias="coverageArea"
    )
    endpoint: PyList[Reference] | None = Field(
        None, alias="endpoint", serialization_alias="endpoint"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    network: PyList[Reference] | None = Field(
        None, alias="network", serialization_alias="network"
    )
    owned_by: Reference | None = Field(
        None, alias="ownedBy", serialization_alias="ownedBy"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    plan: PyList[InsurancePlanPlan] | None = Field(
        None, alias="plan", serialization_alias="plan"
    )
    status: Literal["draft", "active", "retired", "unknown"] | None = Field(
        None, alias="status", serialization_alias="status"
    )
    type: PyList[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) -> InsurancePlan:
        return cls.model_validate_json(json)
