# 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 ...commons.types.claim_id import ClaimId
from ...era.types.era import Era
from ...service_lines.resources.v_2.types.service_line import ServiceLine
from .claim_status import ClaimStatus


class Claim(pydantic.BaseModel):
    """
    Examples
    --------
    import datetime
    import uuid

    from candid import (
        Claim,
        ClaimStatus,
        DateRangeOptionalEnd,
        Era,
        FacilityTypeCode,
        ProcedureModifier,
        ServiceLineUnits,
    )
    from candid.resources.service_lines.v_2 import (
        DenialReasonContent,
        ServiceLine,
        ServiceLineDenialReason,
    )

    Claim(
        claim_id=uuid.UUID(
            "dd9d7f82-37b5-449d-aa63-26925398335b",
        ),
        status=ClaimStatus.BILLER_RECEIVED,
        clearinghouse="Change Healthcare",
        clearinghouse_claim_id="5BA7C3AB-2BC2-496C-8B10-6CAC73D0729D",
        payer_claim_id="9BB9F259-9756-4F16-8F53-9DBB9F7EB1BB",
        service_lines=[
            ServiceLine(
                modifiers=[ProcedureModifier.TWENTY_TWO],
                charge_amount_cents=10000,
                allowed_amount_cents=8000,
                paid_amount_cents=8000,
                patient_responsibility_cents=2000,
                diagnosis_id_zero=uuid.UUID(
                    "4ac84bcd-12f5-4f86-a57b-e06749127c98",
                ),
                diagnosis_id_one=uuid.UUID(
                    "eea5ca5a-8b43-45fd-8cbd-c6cc1103e759",
                ),
                diagnosis_id_two=uuid.UUID(
                    "5c4aa029-2db9-4202-916e-e93c708f65ff",
                ),
                diagnosis_id_three=uuid.UUID(
                    "81795126-a3ac-443c-b47e-7259a16ab4a2",
                ),
                denial_reason=ServiceLineDenialReason(
                    reason=DenialReasonContent.AUTHORIZATION_REQUIRED,
                ),
                place_of_service_code=FacilityTypeCode.PHARMACY,
                service_line_id=uuid.UUID(
                    "ced00f23-6e68-4678-9dbc-f5aa2969a565",
                ),
                procedure_code="99213",
                quantity="1",
                units=ServiceLineUnits.MJ,
                claim_id=uuid.UUID(
                    "026a1fb8-748e-4859-a2d7-3ea9e07d25ae",
                ),
                date_of_service_range=DateRangeOptionalEnd(
                    start_date="2023-01-01",
                    end_date="2023-01-03",
                ),
                date_of_service=datetime.date.fromisoformat(
                    "2023-01-01",
                ),
                end_date_of_service=datetime.date.fromisoformat(
                    "2023-01-03",
                ),
            )
        ],
        eras=[
            Era(
                era_id=uuid.UUID(
                    "4d844ef1-2253-43cd-a4f1-6db7e65cb54b",
                ),
                check_number="CHK12345",
                check_date="2023-10-12",
            )
        ],
    )
    """

    claim_id: ClaimId
    status: ClaimStatus
    clearinghouse: typing.Optional[str] = None
    clearinghouse_claim_id: typing.Optional[str] = None
    payer_claim_id: typing.Optional[str] = None
    clia_number: typing.Optional[str] = None
    service_lines: typing.List[ServiceLine]
    eras: typing.List[Era]

    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.forbid
        json_encoders = {dt.datetime: serialize_datetime}
