# coding: utf-8

"""
    Artifact Keeper API

    Enterprise artifact registry supporting 45+ package formats.

    The version of the OpenAPI document: 1.0.0-rc.3
    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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from artifact_keeper_client.models.db_pool_stats import DbPoolStats
from artifact_keeper_client.models.health_checks import HealthChecks
from typing import Optional, Set
from typing_extensions import Self

class HealthResponse(BaseModel):
    """
    HealthResponse
    """ # noqa: E501
    checks: HealthChecks
    commit: Optional[StrictStr] = None
    db_pool: Optional[DbPoolStats] = None
    demo_mode: StrictBool
    dirty: Optional[StrictBool] = None
    status: StrictStr
    version: StrictStr
    __properties: ClassVar[List[str]] = ["checks", "commit", "db_pool", "demo_mode", "dirty", "status", "version"]

    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 HealthResponse 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 checks
        if self.checks:
            _dict['checks'] = self.checks.to_dict()
        # override the default output from pydantic by calling `to_dict()` of db_pool
        if self.db_pool:
            _dict['db_pool'] = self.db_pool.to_dict()
        # set to None if commit (nullable) is None
        # and model_fields_set contains the field
        if self.commit is None and "commit" in self.model_fields_set:
            _dict['commit'] = None

        # set to None if db_pool (nullable) is None
        # and model_fields_set contains the field
        if self.db_pool is None and "db_pool" in self.model_fields_set:
            _dict['db_pool'] = None

        # set to None if dirty (nullable) is None
        # and model_fields_set contains the field
        if self.dirty is None and "dirty" in self.model_fields_set:
            _dict['dirty'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "checks": HealthChecks.from_dict(obj["checks"]) if obj.get("checks") is not None else None,
            "commit": obj.get("commit"),
            "db_pool": DbPoolStats.from_dict(obj["db_pool"]) if obj.get("db_pool") is not None else None,
            "demo_mode": obj.get("demo_mode"),
            "dirty": obj.get("dirty"),
            "status": obj.get("status"),
            "version": obj.get("version")
        })
        return _obj


