# 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: 0.81.1
    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, StrictStr
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 typing import Optional, Set
from typing_extensions import Self

class StageProgress(BaseModel):
    """
    Progress tracking for a migration stage.
    """ # noqa: E501
    stage: MigrationStage = Field(description="Stage name")
    status: MigrationStatus = Field(description="Stage status")
    started_at: Optional[datetime] = Field(default=None, description="Stage start time")
    completed_at: Optional[datetime] = Field(default=None, description="Stage completion time")
    progress_percent: Optional[Union[Annotated[float, Field(le=100, strict=True, ge=0)], Annotated[int, Field(le=100, strict=True, ge=0)]]] = Field(default=0, description="Progress %")
    items_total: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=0, description="Total items to process")
    items_completed: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=0, description="Items completed")
    items_failed: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=0, description="Items failed")
    error_message: Optional[StrictStr] = Field(default=None, description="Error if failed")
    __properties: ClassVar[List[str]] = ["stage", "status", "started_at", "completed_at", "progress_percent", "items_total", "items_completed", "items_failed", "error_message"]

    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 StageProgress 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "stage": obj.get("stage"),
            "status": obj.get("status"),
            "started_at": obj.get("started_at"),
            "completed_at": obj.get("completed_at"),
            "progress_percent": obj.get("progress_percent") if obj.get("progress_percent") is not None else 0,
            "items_total": obj.get("items_total") if obj.get("items_total") is not None else 0,
            "items_completed": obj.get("items_completed") if obj.get("items_completed") is not None else 0,
            "items_failed": obj.get("items_failed") if obj.get("items_failed") is not None else 0,
            "error_message": obj.get("error_message")
        })
        return _obj


