# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

import pydantic

from ........core.datetime_utils import serialize_datetime
from ........core.pydantic_utilities import deep_union_pydantic_dicts
from .....common.types.patient_id import PatientId
from .....common.types.relationship import Relationship
from .coverage_benefits import CoverageBenefits
from .coverage_status import CoverageStatus
from .eligibility_check_metadata import EligibilityCheckMetadata
from .insurance_plan import InsurancePlan
from .subscriber import Subscriber


class MutableCoverage(pydantic.BaseModel):
    status: CoverageStatus = pydantic.Field()
    """
    The status indiciating if the coverage is active or not.
    """

    subscriber: Subscriber = pydantic.Field()
    """
    The party who has signed-up for or 'owns' the contractual relationship to the policy or to whom the benefit of the policy for services rendered to them or their family is due.
    """

    relationship: Relationship = pydantic.Field()
    """
    The relationship of beneficiary (patient) to the subscriber. https://hl7.org/fhir/valueset-relationship.html
    """

    patient: PatientId = pydantic.Field()
    """
    The patient who benefits from the insurance coverage
    """

    insurance_plan: InsurancePlan
    verified: bool = pydantic.Field()
    """
    A boolean indicating if the coverage has been verified by a user.
    """

    eligibility_checks: typing.Optional[typing.List[EligibilityCheckMetadata]] = pydantic.Field(default=None)
    """
    A list of eligibility check metadata that have been initiated on this coverage.
    """

    benefits: typing.Optional[CoverageBenefits] = pydantic.Field(default=None)
    """
    The eligibility of the patient for the coverage, manually verified by users.
    """

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}

        return deep_union_pydantic_dicts(
            super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
        )

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic.Extra.allow
        json_encoders = {dt.datetime: serialize_datetime}
