# coding: utf-8

"""
    The Jira Cloud platform REST API

    Jira Cloud platform REST API documentation

    The version of the OpenAPI document: 1001.0.0-SNAPSHOT-7ce0ee67a52d004425175cea962ad1c1c7200181
    Contact: ecosystem@atlassian.com
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from jira_client.models.history_metadata_participant import HistoryMetadataParticipant
from typing import Optional, Set
from typing_extensions import Self

class HistoryMetadata(BaseModel):
    """
    Details of issue history metadata.
    """ # noqa: E501
    activity_description: Optional[StrictStr] = Field(default=None, description="The activity described in the history record.", alias="activityDescription")
    activity_description_key: Optional[StrictStr] = Field(default=None, description="The key of the activity described in the history record.", alias="activityDescriptionKey")
    actor: Optional[HistoryMetadataParticipant] = Field(default=None, description="Details of the user whose action created the history record.")
    cause: Optional[HistoryMetadataParticipant] = Field(default=None, description="Details of the cause that triggered the creation the history record.")
    description: Optional[StrictStr] = Field(default=None, description="The description of the history record.")
    description_key: Optional[StrictStr] = Field(default=None, description="The description key of the history record.", alias="descriptionKey")
    email_description: Optional[StrictStr] = Field(default=None, description="The description of the email address associated the history record.", alias="emailDescription")
    email_description_key: Optional[StrictStr] = Field(default=None, description="The description key of the email address associated the history record.", alias="emailDescriptionKey")
    extra_data: Optional[Dict[str, StrictStr]] = Field(default=None, description="Additional arbitrary information about the history record.", alias="extraData")
    generator: Optional[HistoryMetadataParticipant] = Field(default=None, description="Details of the system that generated the history record.")
    type: Optional[StrictStr] = Field(default=None, description="The type of the history record.")
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["activityDescription", "activityDescriptionKey", "actor", "cause", "description", "descriptionKey", "emailDescription", "emailDescriptionKey", "extraData", "generator", "type"]

    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 HistoryMetadata 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of actor
        if self.actor:
            _dict['actor'] = self.actor.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cause
        if self.cause:
            _dict['cause'] = self.cause.to_dict()
        # override the default output from pydantic by calling `to_dict()` of generator
        if self.generator:
            _dict['generator'] = self.generator.to_dict()
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

        return _dict

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

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

        _obj = cls.model_validate({
            "activityDescription": obj.get("activityDescription"),
            "activityDescriptionKey": obj.get("activityDescriptionKey"),
            "actor": HistoryMetadataParticipant.from_dict(obj["actor"]) if obj.get("actor") is not None else None,
            "cause": HistoryMetadataParticipant.from_dict(obj["cause"]) if obj.get("cause") is not None else None,
            "description": obj.get("description"),
            "descriptionKey": obj.get("descriptionKey"),
            "emailDescription": obj.get("emailDescription"),
            "emailDescriptionKey": obj.get("emailDescriptionKey"),
            "extraData": obj.get("extraData"),
            "generator": HistoryMetadataParticipant.from_dict(obj["generator"]) if obj.get("generator") is not None else None,
            "type": obj.get("type")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


