# coding: utf-8

"""
    

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

    The version of the OpenAPI document: 
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class BackgroundJobAttempt(BaseModel):
    """
    Telemetry captured for a single execution attempt of a background job
    """ # noqa: E501
    attempt_id: StrictInt = Field(description="Identifier of the attempt", alias="attemptId")
    job_id: StrictInt = Field(description="Identifier of the job that owns this attempt", alias="jobId")
    started_at: Optional[StrictInt] = Field(default=None, description="Attempt start timestamp (milliseconds since epoch)", alias="startedAt")
    finished_at: Optional[StrictInt] = Field(default=None, description="Attempt completion timestamp (milliseconds since epoch)", alias="finishedAt")
    ok: Optional[StrictBool] = Field(default=None, description="Indicates whether the attempt succeeded (null if still running)")
    worker_id: Optional[StrictStr] = Field(default=None, description="Identifier of the worker processing the attempt", alias="workerId")
    status_message: Optional[StrictStr] = Field(default=None, description="Latest status message reported by the worker", alias="statusMessage")
    progress_current: StrictInt = Field(description="Current progress counter value", alias="progressCurrent")
    progress_total: Optional[StrictInt] = Field(default=None, description="Total progress target when known", alias="progressTotal")
    progress_unit: Optional[StrictStr] = Field(default=None, description="Unit label associated with the progress counters", alias="progressUnit")
    progress_updated_at: Optional[StrictInt] = Field(default=None, description="Timestamp when progress was last updated (milliseconds since epoch)", alias="progressUpdatedAt")
    error_message: Optional[StrictStr] = Field(default=None, description="Short error message recorded when the attempt failed", alias="errorMessage")
    error_stacktrace: Optional[StrictStr] = Field(default=None, description="Stack trace captured when the attempt failed, if available", alias="errorStacktrace")
    __properties: ClassVar[List[str]] = ["attemptId", "jobId", "startedAt", "finishedAt", "ok", "workerId", "statusMessage", "progressCurrent", "progressTotal", "progressUnit", "progressUpdatedAt", "errorMessage", "errorStacktrace"]

    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 BackgroundJobAttempt 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,
        )
        # set to None if started_at (nullable) is None
        # and model_fields_set contains the field
        if self.started_at is None and "started_at" in self.model_fields_set:
            _dict['startedAt'] = 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['finishedAt'] = None

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "attemptId": obj.get("attemptId"),
            "jobId": obj.get("jobId"),
            "startedAt": obj.get("startedAt"),
            "finishedAt": obj.get("finishedAt"),
            "ok": obj.get("ok"),
            "workerId": obj.get("workerId"),
            "statusMessage": obj.get("statusMessage"),
            "progressCurrent": obj.get("progressCurrent"),
            "progressTotal": obj.get("progressTotal"),
            "progressUnit": obj.get("progressUnit"),
            "progressUpdatedAt": obj.get("progressUpdatedAt"),
            "errorMessage": obj.get("errorMessage"),
            "errorStacktrace": obj.get("errorStacktrace")
        })
        return _obj


