# coding: utf-8

"""
    virsh-sandbox API

    API for managing virtual machine sandboxes using libvirt

    The version of the OpenAPI document: 0.0.1-beta
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, StrictStr
from typing_extensions import Self

from virsh_sandbox.models.virsh_sandbox_internal_store_command_summary import \
    VirshSandboxInternalStoreCommandSummary
from virsh_sandbox.models.virsh_sandbox_internal_store_package_info import \
    VirshSandboxInternalStorePackageInfo
from virsh_sandbox.models.virsh_sandbox_internal_store_service_change import \
    VirshSandboxInternalStoreServiceChange


class VirshSandboxInternalStoreChangeDiff(BaseModel):
    """
    VirshSandboxInternalStoreChangeDiff
    """  # noqa: E501

    commands_run: Optional[List[VirshSandboxInternalStoreCommandSummary]] = None
    files_added: Optional[List[StrictStr]] = None
    files_modified: Optional[List[StrictStr]] = None
    files_removed: Optional[List[StrictStr]] = None
    packages_added: Optional[List[VirshSandboxInternalStorePackageInfo]] = None
    packages_removed: Optional[List[VirshSandboxInternalStorePackageInfo]] = None
    services_changed: Optional[List[VirshSandboxInternalStoreServiceChange]] = None
    __properties: ClassVar[List[str]] = [
        "commands_run",
        "files_added",
        "files_modified",
        "files_removed",
        "packages_added",
        "packages_removed",
        "services_changed",
    ]

    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 VirshSandboxInternalStoreChangeDiff 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 commands_run (list)
        _items = []
        if self.commands_run:
            for _item_commands_run in self.commands_run:
                if _item_commands_run:
                    _items.append(_item_commands_run.to_dict())
            _dict["commands_run"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in packages_added (list)
        _items = []
        if self.packages_added:
            for _item_packages_added in self.packages_added:
                if _item_packages_added:
                    _items.append(_item_packages_added.to_dict())
            _dict["packages_added"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in packages_removed (list)
        _items = []
        if self.packages_removed:
            for _item_packages_removed in self.packages_removed:
                if _item_packages_removed:
                    _items.append(_item_packages_removed.to_dict())
            _dict["packages_removed"] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in services_changed (list)
        _items = []
        if self.services_changed:
            for _item_services_changed in self.services_changed:
                if _item_services_changed:
                    _items.append(_item_services_changed.to_dict())
            _dict["services_changed"] = _items
        return _dict

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

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

        _obj = cls.model_validate(
            {
                "commands_run": [
                    VirshSandboxInternalStoreCommandSummary.from_dict(_item)
                    for _item in obj["commands_run"]
                ]
                if obj.get("commands_run") is not None
                else None,
                "files_added": obj.get("files_added"),
                "files_modified": obj.get("files_modified"),
                "files_removed": obj.get("files_removed"),
                "packages_added": [
                    VirshSandboxInternalStorePackageInfo.from_dict(_item)
                    for _item in obj["packages_added"]
                ]
                if obj.get("packages_added") is not None
                else None,
                "packages_removed": [
                    VirshSandboxInternalStorePackageInfo.from_dict(_item)
                    for _item in obj["packages_removed"]
                ]
                if obj.get("packages_removed") is not None
                else None,
                "services_changed": [
                    VirshSandboxInternalStoreServiceChange.from_dict(_item)
                    for _item in obj["services_changed"]
                ]
                if obj.get("services_changed") is not None
                else None,
            }
        )
        return _obj
