# 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
from typing import List as PyList, Literal

from fhirschemapy.R4B.base import (
    Annotation,
    BackboneElement,
    CodeableConcept,
    Duration,
    Identifier,
    Quantity,
    Range,
    Ratio,
    Reference,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    detail_boolean: bool | None = Field(
        None, alias="detailBoolean", serialization_alias="detailBoolean"
    )
    detail_codeable_concept: CodeableConcept | None = Field(
        None, alias="detailCodeableConcept", serialization_alias="detailCodeableConcept"
    )
    detail_integer: int | None = Field(
        None, alias="detailInteger", serialization_alias="detailInteger"
    )
    detail_quantity: Quantity | None = Field(
        None, alias="detailQuantity", serialization_alias="detailQuantity"
    )
    detail_range: Range | None = Field(
        None, alias="detailRange", serialization_alias="detailRange"
    )
    detail_ratio: Ratio | None = Field(
        None, alias="detailRatio", serialization_alias="detailRatio"
    )
    detail_string: str | None = Field(
        None, alias="detailString", serialization_alias="detailString"
    )
    due_date: str | None = Field(None, alias="dueDate", serialization_alias="dueDate")
    due_duration: Duration | None = Field(
        None, alias="dueDuration", serialization_alias="dueDuration"
    )
    measure: CodeableConcept | None = Field(
        None, alias="measure", serialization_alias="measure"
    )


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

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

    achievement_status: CodeableConcept | None = Field(
        None, alias="achievementStatus", serialization_alias="achievementStatus"
    )
    addresses: PyList[Reference] | None = Field(
        None, alias="addresses", serialization_alias="addresses"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    description: CodeableConcept = Field(
        alias="description", serialization_alias="description"
    )
    expressed_by: Reference | None = Field(
        None, alias="expressedBy", serialization_alias="expressedBy"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    lifecycle_status: Literal[
        "proposed",
        "planned",
        "accepted",
        "cancelled",
        "entered-in-error",
        "rejected",
        "active",
        "on-hold",
        "completed",
    ] = Field(alias="lifecycleStatus", serialization_alias="lifecycleStatus")
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    outcome_code: PyList[CodeableConcept] | None = Field(
        None, alias="outcomeCode", serialization_alias="outcomeCode"
    )
    outcome_reference: PyList[Reference] | None = Field(
        None, alias="outcomeReference", serialization_alias="outcomeReference"
    )
    priority: CodeableConcept | None = Field(
        None, alias="priority", serialization_alias="priority"
    )
    start_codeable_concept: CodeableConcept | None = Field(
        None, alias="startCodeableConcept", serialization_alias="startCodeableConcept"
    )
    start_date: str | None = Field(
        None, alias="startDate", serialization_alias="startDate"
    )
    status_date: str | None = Field(
        None, alias="statusDate", serialization_alias="statusDate"
    )
    status_reason: str | None = Field(
        None, alias="statusReason", serialization_alias="statusReason"
    )
    subject: Reference = Field(alias="subject", serialization_alias="subject")
    target: PyList[GoalTarget] | None = Field(
        None, alias="target", serialization_alias="target"
    )

    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) -> Goal:
        return cls.model_validate_json(json)
