# 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 BackboneElement, CodeableConcept
from fhirschemapy.R4B.domain_resource import DomainResource


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

    code: Literal[
        "invalid",
        "security",
        "processing",
        "transient",
        "informational",
        "structure",
        "required",
        "value",
        "invariant",
        "login",
        "unknown",
        "expired",
        "forbidden",
        "suppressed",
        "not-supported",
        "duplicate",
        "multiple-matches",
        "not-found",
        "too-long",
        "code-invalid",
        "extension",
        "too-costly",
        "business-rule",
        "conflict",
        "deleted",
        "lock-error",
        "no-store",
        "exception",
        "timeout",
        "incomplete",
        "throttled",
    ] = Field(alias="code", serialization_alias="code")
    details: CodeableConcept | None = Field(
        None, alias="details", serialization_alias="details"
    )
    diagnostics: str | None = Field(
        None, alias="diagnostics", serialization_alias="diagnostics"
    )
    expression: PyList[str] | None = Field(
        None, alias="expression", serialization_alias="expression"
    )
    location: PyList[str] | None = Field(
        None, alias="location", serialization_alias="location"
    )
    severity: Literal["fatal", "error", "warning", "information"] = Field(
        alias="severity", serialization_alias="severity"
    )


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

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

    issue: PyList[OperationOutcomeIssue] = Field(
        alias="issue", serialization_alias="issue"
    )

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