# 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,
    Period,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    coverage: Reference = Field(alias="coverage", serialization_alias="coverage")
    priority: PositiveInt | None = Field(
        None, alias="priority", serialization_alias="priority"
    )


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

    on_hold: bool | None = Field(None, alias="onHold", serialization_alias="onHold")
    party: Reference = Field(alias="party", serialization_alias="party")
    period: Period | None = Field(None, alias="period", serialization_alias="period")


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

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

    coverage: PyList[AccountCoverage] | None = Field(
        None, alias="coverage", serialization_alias="coverage"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    guarantor: PyList[AccountGuarantor] | None = Field(
        None, alias="guarantor", serialization_alias="guarantor"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    owner: Reference | None = Field(None, alias="owner", serialization_alias="owner")
    part_of: Reference | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    service_period: Period | None = Field(
        None, alias="servicePeriod", serialization_alias="servicePeriod"
    )
    status: Literal["active", "inactive", "entered-in-error", "on-hold", "unknown"] = (
        Field(alias="status", serialization_alias="status")
    )
    subject: PyList[Reference] | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    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) -> Account:
        return cls.model_validate_json(json)
