# 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,
    Attachment,
    BackboneElement,
    CodeableConcept,
    Coding,
    Identifier,
    Money,
    Period,
    Quantity,
    Reference,
    Signature,
    Timing,
)
from fhirschemapy.R4B.domain_resource import DomainResource


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

    copyright: str | None = Field(
        None, alias="copyright", serialization_alias="copyright"
    )
    publication_date: str | None = Field(
        None, alias="publicationDate", serialization_alias="publicationDate"
    )
    publication_status: Literal[
        "amended",
        "appended",
        "cancelled",
        "disputed",
        "entered-in-error",
        "executable",
        "executed",
        "negotiable",
        "offered",
        "policy",
        "rejected",
        "renewed",
        "revoked",
        "resolved",
        "terminated",
    ] = Field(alias="publicationStatus", serialization_alias="publicationStatus")
    publisher: Reference | None = Field(
        None, alias="publisher", serialization_alias="publisher"
    )
    sub_type: CodeableConcept | None = Field(
        None, alias="subType", serialization_alias="subType"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    content_attachment: Attachment | None = Field(
        None, alias="contentAttachment", serialization_alias="contentAttachment"
    )
    content_reference: Reference | None = Field(
        None, alias="contentReference", serialization_alias="contentReference"
    )


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

    content_attachment: Attachment | None = Field(
        None, alias="contentAttachment", serialization_alias="contentAttachment"
    )
    content_reference: Reference | None = Field(
        None, alias="contentReference", serialization_alias="contentReference"
    )


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

    content_attachment: Attachment | None = Field(
        None, alias="contentAttachment", serialization_alias="contentAttachment"
    )
    content_reference: Reference | None = Field(
        None, alias="contentReference", serialization_alias="contentReference"
    )


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

    party: Reference = Field(alias="party", serialization_alias="party")
    signature: PyList[Signature] = Field(
        alias="signature", serialization_alias="signature"
    )
    type: Coding = Field(alias="type", serialization_alias="type")


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

    action: PyList[ContractTermAction] | None = Field(
        None, alias="action", serialization_alias="action"
    )
    applies: Period | None = Field(None, alias="applies", serialization_alias="applies")
    asset: PyList[ContractTermAsset] | None = Field(
        None, alias="asset", serialization_alias="asset"
    )
    group: PyList[ContractTerm] | None = Field(
        None, alias="group", serialization_alias="group"
    )
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    issued: str | None = Field(None, alias="issued", serialization_alias="issued")
    offer: ContractTermOffer = Field(alias="offer", serialization_alias="offer")
    security_label: PyList[ContractTermSecurityLabel] | None = Field(
        None, alias="securityLabel", serialization_alias="securityLabel"
    )
    sub_type: CodeableConcept | None = Field(
        None, alias="subType", serialization_alias="subType"
    )
    text: str | None = Field(None, alias="text", serialization_alias="text")
    topic_codeable_concept: CodeableConcept | None = Field(
        None, alias="topicCodeableConcept", serialization_alias="topicCodeableConcept"
    )
    topic_reference: Reference | None = Field(
        None, alias="topicReference", serialization_alias="topicReference"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    context: Reference | None = Field(
        None, alias="context", serialization_alias="context"
    )
    context_link_id: PyList[str] | None = Field(
        None, alias="contextLinkId", serialization_alias="contextLinkId"
    )
    do_not_perform: bool | None = Field(
        None, alias="doNotPerform", serialization_alias="doNotPerform"
    )
    intent: CodeableConcept = Field(alias="intent", serialization_alias="intent")
    link_id: PyList[str] | None = Field(
        None, alias="linkId", serialization_alias="linkId"
    )
    note: PyList[Annotation] | None = Field(
        None, alias="note", serialization_alias="note"
    )
    occurrence_date_time: str | None = Field(
        None, alias="occurrenceDateTime", serialization_alias="occurrenceDateTime"
    )
    occurrence_period: Period | None = Field(
        None, alias="occurrencePeriod", serialization_alias="occurrencePeriod"
    )
    occurrence_timing: Timing | None = Field(
        None, alias="occurrenceTiming", serialization_alias="occurrenceTiming"
    )
    performer: Reference | None = Field(
        None, alias="performer", serialization_alias="performer"
    )
    performer_link_id: PyList[str] | None = Field(
        None, alias="performerLinkId", serialization_alias="performerLinkId"
    )
    performer_role: CodeableConcept | None = Field(
        None, alias="performerRole", serialization_alias="performerRole"
    )
    performer_type: PyList[CodeableConcept] | None = Field(
        None, alias="performerType", serialization_alias="performerType"
    )
    reason: PyList[str] | None = Field(
        None, alias="reason", serialization_alias="reason"
    )
    reason_code: PyList[CodeableConcept] | None = Field(
        None, alias="reasonCode", serialization_alias="reasonCode"
    )
    reason_link_id: PyList[str] | None = Field(
        None, alias="reasonLinkId", serialization_alias="reasonLinkId"
    )
    reason_reference: PyList[Reference] | None = Field(
        None, alias="reasonReference", serialization_alias="reasonReference"
    )
    requester: PyList[Reference] | None = Field(
        None, alias="requester", serialization_alias="requester"
    )
    requester_link_id: PyList[str] | None = Field(
        None, alias="requesterLinkId", serialization_alias="requesterLinkId"
    )
    security_label_number: PyList[int] | None = Field(
        None, alias="securityLabelNumber", serialization_alias="securityLabelNumber"
    )
    status: CodeableConcept = Field(alias="status", serialization_alias="status")
    subject: PyList[ContractTermActionSubject] | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    type: CodeableConcept = Field(alias="type", serialization_alias="type")


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

    reference: PyList[Reference] = Field(
        alias="reference", serialization_alias="reference"
    )
    role: CodeableConcept | None = Field(None, alias="role", serialization_alias="role")


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

    answer: PyList[ContractTermOfferAnswer] | None = Field(
        None, alias="answer", serialization_alias="answer"
    )
    condition: str | None = Field(
        None, alias="condition", serialization_alias="condition"
    )
    context: PyList[ContractTermAssetContext] | None = Field(
        None, alias="context", serialization_alias="context"
    )
    link_id: PyList[str] | None = Field(
        None, alias="linkId", serialization_alias="linkId"
    )
    period: PyList[Period] | None = Field(
        None, alias="period", serialization_alias="period"
    )
    period_type: PyList[CodeableConcept] | None = Field(
        None, alias="periodType", serialization_alias="periodType"
    )
    relationship: Coding | None = Field(
        None, alias="relationship", serialization_alias="relationship"
    )
    scope: CodeableConcept | None = Field(
        None, alias="scope", serialization_alias="scope"
    )
    security_label_number: PyList[int] | None = Field(
        None, alias="securityLabelNumber", serialization_alias="securityLabelNumber"
    )
    subtype: PyList[CodeableConcept] | None = Field(
        None, alias="subtype", serialization_alias="subtype"
    )
    text: str | None = Field(None, alias="text", serialization_alias="text")
    type: PyList[CodeableConcept] | None = Field(
        None, alias="type", serialization_alias="type"
    )
    type_reference: PyList[Reference] | None = Field(
        None, alias="typeReference", serialization_alias="typeReference"
    )
    use_period: PyList[Period] | None = Field(
        None, alias="usePeriod", serialization_alias="usePeriod"
    )
    valued_item: PyList[ContractTermAssetValuedItem] | None = Field(
        None, alias="valuedItem", serialization_alias="valuedItem"
    )


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

    code: PyList[CodeableConcept] | None = Field(
        None, alias="code", serialization_alias="code"
    )
    reference: Reference | None = Field(
        None, alias="reference", serialization_alias="reference"
    )
    text: str | None = Field(None, alias="text", serialization_alias="text")


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

    effective_time: str | None = Field(
        None, alias="effectiveTime", serialization_alias="effectiveTime"
    )
    entity_codeable_concept: CodeableConcept | None = Field(
        None, alias="entityCodeableConcept", serialization_alias="entityCodeableConcept"
    )
    entity_reference: Reference | None = Field(
        None, alias="entityReference", serialization_alias="entityReference"
    )
    factor: float | None = Field(None, alias="factor", serialization_alias="factor")
    identifier: Identifier | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    link_id: PyList[str] | None = Field(
        None, alias="linkId", serialization_alias="linkId"
    )
    net: Money | None = Field(None, alias="net", serialization_alias="net")
    payment: str | None = Field(None, alias="payment", serialization_alias="payment")
    payment_date: str | None = Field(
        None, alias="paymentDate", serialization_alias="paymentDate"
    )
    points: float | None = Field(None, alias="points", serialization_alias="points")
    quantity: Quantity | None = Field(
        None, alias="quantity", serialization_alias="quantity"
    )
    recipient: Reference | None = Field(
        None, alias="recipient", serialization_alias="recipient"
    )
    responsible: Reference | None = Field(
        None, alias="responsible", serialization_alias="responsible"
    )
    security_label_number: PyList[int] | None = Field(
        None, alias="securityLabelNumber", serialization_alias="securityLabelNumber"
    )
    unit_price: Money | None = Field(
        None, alias="unitPrice", serialization_alias="unitPrice"
    )


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

    answer: PyList[ContractTermOfferAnswer] | None = Field(
        None, alias="answer", serialization_alias="answer"
    )
    decision: CodeableConcept | None = Field(
        None, alias="decision", serialization_alias="decision"
    )
    decision_mode: PyList[CodeableConcept] | None = Field(
        None, alias="decisionMode", serialization_alias="decisionMode"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    link_id: PyList[str] | None = Field(
        None, alias="linkId", serialization_alias="linkId"
    )
    party: PyList[ContractTermOfferParty] | None = Field(
        None, alias="party", serialization_alias="party"
    )
    security_label_number: PyList[int] | None = Field(
        None, alias="securityLabelNumber", serialization_alias="securityLabelNumber"
    )
    text: str | None = Field(None, alias="text", serialization_alias="text")
    topic: Reference | None = Field(None, alias="topic", serialization_alias="topic")
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")


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

    value_attachment: Attachment | None = Field(
        None, alias="valueAttachment", serialization_alias="valueAttachment"
    )
    value_boolean: bool | None = Field(
        None, alias="valueBoolean", serialization_alias="valueBoolean"
    )
    value_coding: Coding | None = Field(
        None, alias="valueCoding", serialization_alias="valueCoding"
    )
    value_date: str | None = Field(
        None, alias="valueDate", serialization_alias="valueDate"
    )
    value_date_time: str | None = Field(
        None, alias="valueDateTime", serialization_alias="valueDateTime"
    )
    value_decimal: float | None = Field(
        None, alias="valueDecimal", serialization_alias="valueDecimal"
    )
    value_integer: int | None = Field(
        None, alias="valueInteger", serialization_alias="valueInteger"
    )
    value_quantity: Quantity | None = Field(
        None, alias="valueQuantity", serialization_alias="valueQuantity"
    )
    value_reference: Reference | None = Field(
        None, alias="valueReference", serialization_alias="valueReference"
    )
    value_string: str | None = Field(
        None, alias="valueString", serialization_alias="valueString"
    )
    value_time: str | None = Field(
        None, alias="valueTime", serialization_alias="valueTime"
    )
    value_uri: str | None = Field(
        None, alias="valueUri", serialization_alias="valueUri"
    )


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

    reference: PyList[Reference] = Field(
        alias="reference", serialization_alias="reference"
    )
    role: CodeableConcept = Field(alias="role", serialization_alias="role")


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

    category: PyList[Coding] | None = Field(
        None, alias="category", serialization_alias="category"
    )
    classification: Coding = Field(
        alias="classification", serialization_alias="classification"
    )
    control: PyList[Coding] | None = Field(
        None, alias="control", serialization_alias="control"
    )
    number: PyList[int] | None = Field(
        None, alias="number", serialization_alias="number"
    )


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

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

    alias: PyList[str] | None = Field(None, alias="alias", serialization_alias="alias")
    applies: Period | None = Field(None, alias="applies", serialization_alias="applies")
    author: Reference | None = Field(None, alias="author", serialization_alias="author")
    authority: PyList[Reference] | None = Field(
        None, alias="authority", serialization_alias="authority"
    )
    content_definition: ContractContentDefinition | None = Field(
        None, alias="contentDefinition", serialization_alias="contentDefinition"
    )
    content_derivative: CodeableConcept | None = Field(
        None, alias="contentDerivative", serialization_alias="contentDerivative"
    )
    domain: PyList[Reference] | None = Field(
        None, alias="domain", serialization_alias="domain"
    )
    expiration_type: CodeableConcept | None = Field(
        None, alias="expirationType", serialization_alias="expirationType"
    )
    friendly: PyList[ContractFriendly] | None = Field(
        None, alias="friendly", serialization_alias="friendly"
    )
    identifier: PyList[Identifier] | None = Field(
        None, alias="identifier", serialization_alias="identifier"
    )
    instantiates_canonical: Reference | None = Field(
        None, alias="instantiatesCanonical", serialization_alias="instantiatesCanonical"
    )
    instantiates_uri: str | None = Field(
        None, alias="instantiatesUri", serialization_alias="instantiatesUri"
    )
    issued: str | None = Field(None, alias="issued", serialization_alias="issued")
    legal: PyList[ContractLegal] | None = Field(
        None, alias="legal", serialization_alias="legal"
    )
    legally_binding_attachment: Attachment | None = Field(
        None,
        alias="legallyBindingAttachment",
        serialization_alias="legallyBindingAttachment",
    )
    legally_binding_reference: Reference | None = Field(
        None,
        alias="legallyBindingReference",
        serialization_alias="legallyBindingReference",
    )
    legal_state: CodeableConcept | None = Field(
        None, alias="legalState", serialization_alias="legalState"
    )
    name: str | None = Field(None, alias="name", serialization_alias="name")
    relevant_history: PyList[Reference] | None = Field(
        None, alias="relevantHistory", serialization_alias="relevantHistory"
    )
    rule: PyList[ContractRule] | None = Field(
        None, alias="rule", serialization_alias="rule"
    )
    scope: CodeableConcept | None = Field(
        None, alias="scope", serialization_alias="scope"
    )
    signer: PyList[ContractSigner] | None = Field(
        None, alias="signer", serialization_alias="signer"
    )
    site: PyList[Reference] | None = Field(
        None, alias="site", serialization_alias="site"
    )
    status: (
        Literal[
            "amended",
            "appended",
            "cancelled",
            "disputed",
            "entered-in-error",
            "executable",
            "executed",
            "negotiable",
            "offered",
            "policy",
            "rejected",
            "renewed",
            "revoked",
            "resolved",
            "terminated",
        ]
        | None
    ) = Field(None, alias="status", serialization_alias="status")
    subject: PyList[Reference] | None = Field(
        None, alias="subject", serialization_alias="subject"
    )
    subtitle: str | None = Field(None, alias="subtitle", serialization_alias="subtitle")
    sub_type: PyList[CodeableConcept] | None = Field(
        None, alias="subType", serialization_alias="subType"
    )
    supporting_info: PyList[Reference] | None = Field(
        None, alias="supportingInfo", serialization_alias="supportingInfo"
    )
    term: PyList[ContractTerm] | None = Field(
        None, alias="term", serialization_alias="term"
    )
    title: str | None = Field(None, alias="title", serialization_alias="title")
    topic_codeable_concept: CodeableConcept | None = Field(
        None, alias="topicCodeableConcept", serialization_alias="topicCodeableConcept"
    )
    topic_reference: Reference | None = Field(
        None, alias="topicReference", serialization_alias="topicReference"
    )
    type: CodeableConcept | None = Field(None, alias="type", serialization_alias="type")
    url: str | None = Field(None, alias="url", serialization_alias="url")
    version: str | None = Field(None, alias="version", serialization_alias="version")

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