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


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

    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    name: str = Field(alias="name", serialization_alias="name")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    name: str | None = Field(None, alias="name", serialization_alias="name")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

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

    arm: PyList[ResearchStudyArm] | None = Field(
        None, alias="arm", serialization_alias="arm"
    )
    category: PyList[CodeableConcept] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    condition: PyList[CodeableConcept] | None = Field(
        None, alias="condition", serialization_alias="condition"
    )
    contact: PyList[ContactDetail] | None = Field(
        None, alias="contact", serialization_alias="contact"
    )
    description: str | None = Field(
        None, alias="description", serialization_alias="description"
    )
    enrollment: PyList[Reference] | None = Field(
        None, alias="enrollment", serialization_alias="enrollment"
    )
    focus: PyList[CodeableConcept] | None = Field(
        None, alias="focus", serialization_alias="focus"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    keyword: PyList[CodeableConcept] | None = Field(
        None, alias="keyword", serialization_alias="keyword"
    )
    location: PyList[CodeableConcept] | None = Field(
        None, alias="location", serialization_alias="location"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    objective: PyList[ResearchStudyObjective] | None = Field(
        None, alias="objective", serialization_alias="objective"
    )
    part_of: PyList[Reference] | None = Field(
        None, alias="partOf", serialization_alias="partOf"
    )
    period: Period | None = Field(None, alias="period", serialization_alias="period")
    phase: CodeableConcept | None = Field(
        None, alias="phase", serialization_alias="phase"
    )
    primary_purpose_type: CodeableConcept | None = Field(
        None, alias="primaryPurposeType", serialization_alias="primaryPurposeType"
    )
    principal_investigator: Reference | None = Field(
        None, alias="principalInvestigator", serialization_alias="principalInvestigator"
    )
    protocol: PyList[Reference] | None = Field(
        None, alias="protocol", serialization_alias="protocol"
    )
    reason_stopped: CodeableConcept | None = Field(
        None, alias="reasonStopped", serialization_alias="reasonStopped"
    )
    related_artifact: PyList[RelatedArtifact] | None = Field(
        None, alias="relatedArtifact", serialization_alias="relatedArtifact"
    )
    site: PyList[Reference] | None = Field(
        None, alias="site", serialization_alias="site"
    )
    sponsor: Reference | None = Field(
        None, alias="sponsor", serialization_alias="sponsor"
    )
    status: Literal[
        "active",
        "administratively-completed",
        "approved",
        "closed-to-accrual",
        "closed-to-accrual-and-intervention",
        "completed",
        "disapproved",
        "in-review",
        "temporarily-closed-to-accrual",
        "temporarily-closed-to-accrual-and-intervention",
        "withdrawn",
    ] = Field(alias="status", serialization_alias="status")
    title: str | None = Field(None, alias="title", serialization_alias="title")

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