# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from mixpeek.models.migration_stage import MigrationStage
from mixpeek.models.migration_status import MigrationStatus
from mixpeek.models.resource_progress import ResourceProgress
from mixpeek.models.stage_progress import StageProgress
from typing import Optional, Set
from typing_extensions import Self

class MigrationProgress(BaseModel):
    """
    Overall progress tracking for a migration.
    """ # noqa: E501
    overall_status: MigrationStatus = Field(description="Overall migration status")
    overall_progress_percent: Optional[Union[Annotated[float, Field(le=100.0, strict=True, ge=0.0)], Annotated[int, Field(le=100, strict=True, ge=0)]]] = Field(default=0.0, description="Overall progress %")
    current_stage: Optional[MigrationStage] = Field(default=None, description="Currently executing stage")
    stages: Optional[List[StageProgress]] = Field(default=None, description="Progress for each stage")
    resources: Optional[List[ResourceProgress]] = Field(default=None, description="Progress for each resource")
    started_at: Optional[datetime] = Field(default=None, description="Migration start time")
    estimated_completion: Optional[datetime] = Field(default=None, description="Estimated completion time")
    __properties: ClassVar[List[str]] = ["overall_status", "overall_progress_percent", "current_stage", "stages", "resources", "started_at", "estimated_completion"]

    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 MigrationProgress 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 stages (list)
        _items = []
        if self.stages:
            for _item_stages in self.stages:
                if _item_stages:
                    _items.append(_item_stages.to_dict())
            _dict['stages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in resources (list)
        _items = []
        if self.resources:
            for _item_resources in self.resources:
                if _item_resources:
                    _items.append(_item_resources.to_dict())
            _dict['resources'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "overall_status": obj.get("overall_status"),
            "overall_progress_percent": obj.get("overall_progress_percent") if obj.get("overall_progress_percent") is not None else 0.0,
            "current_stage": obj.get("current_stage"),
            "stages": [StageProgress.from_dict(_item) for _item in obj["stages"]] if obj.get("stages") is not None else None,
            "resources": [ResourceProgress.from_dict(_item) for _item in obj["resources"]] if obj.get("resources") is not None else None,
            "started_at": obj.get("started_at"),
            "estimated_completion": obj.get("estimated_completion")
        })
        return _obj


