# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class UpdateRuleRequest(BaseModel):
    """
    UpdateRuleRequest
    """ # noqa: E501
    allowed_licenses: Optional[List[StrictStr]] = None
    auto_promote: Optional[StrictBool] = None
    is_enabled: Optional[StrictBool] = None
    max_artifact_age_days: Optional[StrictInt] = None
    max_cve_severity: Optional[StrictStr] = None
    min_health_score: Optional[StrictInt] = None
    min_staging_hours: Optional[StrictInt] = None
    name: Optional[StrictStr] = None
    require_signature: Optional[StrictBool] = None
    __properties: ClassVar[List[str]] = ["allowed_licenses", "auto_promote", "is_enabled", "max_artifact_age_days", "max_cve_severity", "min_health_score", "min_staging_hours", "name", "require_signature"]

    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 UpdateRuleRequest 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,
        )
        # set to None if allowed_licenses (nullable) is None
        # and model_fields_set contains the field
        if self.allowed_licenses is None and "allowed_licenses" in self.model_fields_set:
            _dict['allowed_licenses'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "allowed_licenses": obj.get("allowed_licenses"),
            "auto_promote": obj.get("auto_promote"),
            "is_enabled": obj.get("is_enabled"),
            "max_artifact_age_days": obj.get("max_artifact_age_days"),
            "max_cve_severity": obj.get("max_cve_severity"),
            "min_health_score": obj.get("min_health_score"),
            "min_staging_hours": obj.get("min_staging_hours"),
            "name": obj.get("name"),
            "require_signature": obj.get("require_signature")
        })
        return _obj


