# 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.street_address_long_zip import StreetAddressLongZip
from .encounter_provider_base import EncounterProviderBase


class BillingProvider(EncounterProviderBase):
    """
    The billing provider is the provider or business entity submitting the claim.
    Billing provider may be, but is not necessarily, the same person/NPI as the rendering provider.
    From a payer's perspective, this represents the person or entity being reimbursed.
    When a contract exists with the target payer, the billing provider should be the entity contracted with the payer.
    In some circumstances, this will be an individual provider. In that case, submit that provider's NPI and the
    tax ID (TIN) that the provider gave to the payer during contracting.
    In other cases, the billing entity will be a medical group. If so, submit the group NPI and the group's tax ID.
    Box 33 on the CMS-1500 claim form.
    """

    address: StreetAddressLongZip
    tax_id: str = pydantic.Field()
    """
    If the provider has a contract with insurance, this must be the same tax ID given to the payer on an IRS W-9 form completed during contracting.
    """

    npi: str
    taxonomy_code: typing.Optional[str] = None

    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
        allow_population_by_field_name = True
        populate_by_name = True
        extra = pydantic.Extra.forbid
        json_encoders = {dt.datetime: serialize_datetime}
