# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class BackgroundJobSummary(BaseModel):
    """
    Summary of the most recent background job execution for a resource
    """ # noqa: E501
    job_id: StrictInt = Field(description="Database identifier of the background job", alias="jobId")
    job_type: StrictStr = Field(description="Logical job type dispatched by the background job framework", alias="jobType")
    status: StrictStr = Field(description="Current status of the background job")
    attempts: StrictInt = Field(description="Number of attempts started so far")
    max_attempts: StrictInt = Field(description="Maximum number of attempts allowed for this job", alias="maxAttempts")
    run_at: Optional[StrictInt] = Field(default=None, description="Timestamp when the job becomes eligible to run (milliseconds since epoch)", alias="runAt")
    lease_until: Optional[StrictInt] = Field(default=None, description="Lease expiration timestamp if the job is currently running (milliseconds since epoch)", alias="leaseUntil")
    locked_by: Optional[StrictStr] = Field(default=None, description="Identifier of the worker currently holding the lease, if any", alias="lockedBy")
    last_error: Optional[StrictStr] = Field(default=None, description="Most recent short error message if the job failed", alias="lastError")
    updated_at: Optional[StrictInt] = Field(default=None, description="Timestamp when the job row was last updated (milliseconds since epoch)", alias="updatedAt")
    __properties: ClassVar[List[str]] = ["jobId", "jobType", "status", "attempts", "maxAttempts", "runAt", "leaseUntil", "lockedBy", "lastError", "updatedAt"]

    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 BackgroundJobSummary 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 run_at (nullable) is None
        # and model_fields_set contains the field
        if self.run_at is None and "run_at" in self.model_fields_set:
            _dict['runAt'] = None

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "jobId": obj.get("jobId"),
            "jobType": obj.get("jobType"),
            "status": obj.get("status"),
            "attempts": obj.get("attempts"),
            "maxAttempts": obj.get("maxAttempts"),
            "runAt": obj.get("runAt"),
            "leaseUntil": obj.get("leaseUntil"),
            "lockedBy": obj.get("lockedBy"),
            "lastError": obj.get("lastError"),
            "updatedAt": obj.get("updatedAt")
        })
        return _obj


