# coding: utf-8

"""
Cybee API

No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

The version of the OpenAPI document: 0.42.0
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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from cybee_sdk.api.models.plan_status import PlanStatus
from cybee_sdk.api.models.restore_summary import RestoreSummary
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python


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

    id: UUID
    task_id: Optional[UUID] = None
    snapshot_id: Optional[StrictStr] = None
    agent_id: UUID
    programmed_at: Optional[datetime] = None
    repository_id: UUID
    started_at: datetime
    finished_at: Optional[datetime] = None
    plan_config: Optional[StrictStr] = None
    plan_id: UUID
    plan_type: StrictStr
    status: Optional[PlanStatus] = None
    restore_summary: Optional[RestoreSummary] = None
    errors: Optional[List[UUID]] = None
    __properties: ClassVar[List[str]] = [
        "id",
        "task_id",
        "snapshot_id",
        "agent_id",
        "programmed_at",
        "repository_id",
        "started_at",
        "finished_at",
        "plan_config",
        "plan_id",
        "plan_type",
        "status",
        "restore_summary",
        "errors",
    ]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of RestorePlanRun 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 restore_summary
        if self.restore_summary:
            _dict["restore_summary"] = self.restore_summary.to_dict()
        # set to None if task_id (nullable) is None
        # and model_fields_set contains the field
        if self.task_id is None and "task_id" in self.model_fields_set:
            _dict["task_id"] = None

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of RestorePlanRun 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"),
                "task_id": obj.get("task_id"),
                "snapshot_id": obj.get("snapshot_id"),
                "agent_id": obj.get("agent_id"),
                "programmed_at": obj.get("programmed_at"),
                "repository_id": obj.get("repository_id"),
                "started_at": obj.get("started_at"),
                "finished_at": obj.get("finished_at"),
                "plan_config": obj.get("plan_config"),
                "plan_id": obj.get("plan_id"),
                "plan_type": obj.get("plan_type"),
                "status": obj.get("status"),
                "restore_summary": RestoreSummary.from_dict(obj["restore_summary"])
                if obj.get("restore_summary") is not None
                else None,
                "errors": obj.get("errors"),
            }
        )
        return _obj
