# coding: utf-8

"""
    Snowstorm

    SNOMED CT Terminology Server REST API

    The version of the OpenAPI document: 10.8.2
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from snowstorm_client.models.concept_mini import ConceptMini
from typing import Optional, Set
from typing_extensions import Self

class CodeSystem(BaseModel):
    """
    CodeSystem
    """ # noqa: E501
    name: Optional[StrictStr] = None
    owner: Optional[StrictStr] = None
    short_name: StrictStr = Field(alias="shortName")
    branch_path: Annotated[str, Field(strict=True)] = Field(alias="branchPath")
    dependant_version_effective_time: Optional[StrictInt] = Field(default=None, alias="dependantVersionEffectiveTime")
    daily_build_available: Optional[StrictBool] = Field(default=None, alias="dailyBuildAvailable")
    latest_daily_build: Optional[StrictStr] = Field(default=None, alias="latestDailyBuild")
    country_code: Optional[StrictStr] = Field(default=None, alias="countryCode")
    default_language_code: Optional[StrictStr] = Field(default=None, alias="defaultLanguageCode")
    default_language_reference_sets: Optional[List[StrictStr]] = Field(default=None, alias="defaultLanguageReferenceSets")
    maintainer_type: Optional[StrictStr] = Field(default=None, alias="maintainerType")
    latest_version: Optional[CodeSystemVersion] = Field(default=None, alias="latestVersion")
    languages: Optional[Dict[str, StrictStr]] = None
    modules: Optional[List[ConceptMini]] = None
    user_roles: Optional[List[StrictStr]] = Field(default=None, alias="userRoles")
    __properties: ClassVar[List[str]] = ["name", "owner", "shortName", "branchPath", "dependantVersionEffectiveTime", "dailyBuildAvailable", "latestDailyBuild", "countryCode", "defaultLanguageCode", "defaultLanguageReferenceSets", "maintainerType", "latestVersion", "languages", "modules", "userRoles"]

    @field_validator('branch_path')
    def branch_path_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"MAIN.*", value):
            raise ValueError(r"must validate the regular expression /MAIN.*/")
        return value

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CodeSystem from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of latest_version
        if self.latest_version:
            _dict['latestVersion'] = self.latest_version.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in modules (list)
        _items = []
        if self.modules:
            for _item_modules in self.modules:
                if _item_modules:
                    _items.append(_item_modules.to_dict())
            _dict['modules'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CodeSystem from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "owner": obj.get("owner"),
            "shortName": obj.get("shortName"),
            "branchPath": obj.get("branchPath"),
            "dependantVersionEffectiveTime": obj.get("dependantVersionEffectiveTime"),
            "dailyBuildAvailable": obj.get("dailyBuildAvailable"),
            "latestDailyBuild": obj.get("latestDailyBuild"),
            "countryCode": obj.get("countryCode"),
            "defaultLanguageCode": obj.get("defaultLanguageCode"),
            "defaultLanguageReferenceSets": obj.get("defaultLanguageReferenceSets"),
            "maintainerType": obj.get("maintainerType"),
            "latestVersion": CodeSystemVersion.from_dict(obj["latestVersion"]) if obj.get("latestVersion") is not None else None,
            "languages": obj.get("languages"),
            "modules": [ConceptMini.from_dict(_item) for _item in obj["modules"]] if obj.get("modules") is not None else None,
            "userRoles": obj.get("userRoles")
        })
        return _obj

from snowstorm_client.models.code_system_version import CodeSystemVersion
# TODO: Rewrite to not use raise_errors
CodeSystem.model_rebuild(raise_errors=False)

