# 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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from artifact_keeper_client.models.check_summary import CheckSummary
from typing import Optional, Set
from typing_extensions import Self

class ArtifactHealthResponse(BaseModel):
    """
    ArtifactHealthResponse
    """ # noqa: E501
    artifact_id: StrictStr
    checks: List[CheckSummary]
    checks_passed: StrictInt
    checks_total: StrictInt
    critical_issues: StrictInt
    health_grade: StrictStr
    health_score: StrictInt
    last_checked_at: Optional[datetime] = None
    license_score: Optional[StrictInt] = None
    metadata_score: Optional[StrictInt] = None
    quality_score: Optional[StrictInt] = None
    security_score: Optional[StrictInt] = None
    total_issues: StrictInt
    __properties: ClassVar[List[str]] = ["artifact_id", "checks", "checks_passed", "checks_total", "critical_issues", "health_grade", "health_score", "last_checked_at", "license_score", "metadata_score", "quality_score", "security_score", "total_issues"]

    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 ArtifactHealthResponse 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 each item in checks (list)
        _items = []
        if self.checks:
            for _item_checks in self.checks:
                if _item_checks:
                    _items.append(_item_checks.to_dict())
            _dict['checks'] = _items
        # set to None if last_checked_at (nullable) is None
        # and model_fields_set contains the field
        if self.last_checked_at is None and "last_checked_at" in self.model_fields_set:
            _dict['last_checked_at'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "artifact_id": obj.get("artifact_id"),
            "checks": [CheckSummary.from_dict(_item) for _item in obj["checks"]] if obj.get("checks") is not None else None,
            "checks_passed": obj.get("checks_passed"),
            "checks_total": obj.get("checks_total"),
            "critical_issues": obj.get("critical_issues"),
            "health_grade": obj.get("health_grade"),
            "health_score": obj.get("health_score"),
            "last_checked_at": obj.get("last_checked_at"),
            "license_score": obj.get("license_score"),
            "metadata_score": obj.get("metadata_score"),
            "quality_score": obj.get("quality_score"),
            "security_score": obj.get("security_score"),
            "total_issues": obj.get("total_issues")
        })
        return _obj


