# coding: utf-8

"""
    Artifact Keeper API

    REST API for Artifact Keeper, an open-source universal artifact registry. Covers user management, repositories, artifacts, search, security scanning, SBOM, dependency tracking, SSO, analytics, monitoring, telemetry, lifecycle policies, plugins, edge nodes, migration, and administration. Format-specific protocol endpoints (npm, PyPI, Maven, Docker/OCI, etc.) are not included; those follow their respective upstream specifications.

    The version of the OpenAPI document: 1.0.0-a2
    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, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class PromotionHistoryEntry(BaseModel):
    """
    PromotionHistoryEntry
    """ # noqa: E501
    id: StrictStr
    artifact_id: StrictStr
    artifact_path: StrictStr = Field(description="Path of the artifact at the time of promotion.")
    source_repo_key: StrictStr = Field(description="Repository key the artifact was promoted from.")
    target_repo_key: StrictStr = Field(description="Repository key the artifact was promoted to.")
    promoted_by: Optional[StrictStr] = Field(default=None, description="User ID of the operator who initiated the promotion.")
    promoted_by_username: Optional[StrictStr] = Field(default=None, description="Username of the operator who initiated the promotion.")
    policy_result: Optional[Dict[str, Any]] = Field(default=None, description="Serialised result of the promotion policy evaluation, null if skipped.")
    notes: Optional[StrictStr] = Field(default=None, description="Free-text notes attached to the promotion.")
    created_at: datetime
    __properties: ClassVar[List[str]] = ["id", "artifact_id", "artifact_path", "source_repo_key", "target_repo_key", "promoted_by", "promoted_by_username", "policy_result", "notes", "created_at"]

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "artifact_id": obj.get("artifact_id"),
            "artifact_path": obj.get("artifact_path"),
            "source_repo_key": obj.get("source_repo_key"),
            "target_repo_key": obj.get("target_repo_key"),
            "promoted_by": obj.get("promoted_by"),
            "promoted_by_username": obj.get("promoted_by_username"),
            "policy_result": obj.get("policy_result"),
            "notes": obj.get("notes"),
            "created_at": obj.get("created_at")
        })
        return _obj


