# coding: utf-8

"""
    WordLift API

    WordLift API

    The version of the OpenAPI document: 1.0
    Contact: hello@wordlift.io
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Optional, Set
from typing_extensions import Self

class JobResponse(BaseModel):
    """
    JobResponse
    """ # noqa: E501
    job_id: StrictStr = Field(description="Unique job identifier.")
    graph_id: StrictStr = Field(description="Public WordLift graph identifier.")
    snapshot_date: StrictStr = Field(description="Logical KPI day targeted by the job.")
    status: StrictStr = Field(description="Current job status.")
    stage: StrictStr = Field(description="Current or last completed job stage. Cloned snapshots use `clone`.")
    started_at: Optional[StrictStr] = None
    finished_at: Optional[StrictStr] = None
    heartbeat_at: Optional[StrictStr] = None
    documents_seen: Optional[StrictInt] = None
    documents_transformed: Optional[StrictInt] = None
    triple_rows_written: Optional[StrictInt] = None
    issues_written: Optional[StrictInt] = None
    retry_count: Optional[StrictInt] = None
    error_code: Optional[StrictStr] = None
    error_message: Optional[StrictStr] = None
    account_dataset_id: Optional[StrictStr] = None
    website_url: Optional[StrictStr] = None
    stage_timings_json: Optional[Dict[str, Union[StrictFloat, StrictInt]]] = None
    runtime_profile_json: Optional[Dict[str, Any]] = None
    additional_properties: Dict[str, Any] = {}
    __properties: ClassVar[List[str]] = ["job_id", "graph_id", "snapshot_date", "status", "stage", "started_at", "finished_at", "heartbeat_at", "documents_seen", "documents_transformed", "triple_rows_written", "issues_written", "retry_count", "error_code", "error_message", "account_dataset_id", "website_url", "stage_timings_json", "runtime_profile_json"]

    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 JobResponse 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.
        * Fields in `self.additional_properties` are added to the output dict.
        """
        excluded_fields: Set[str] = set([
            "additional_properties",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # puts key-value pairs in additional_properties in the top level
        if self.additional_properties is not None:
            for _key, _value in self.additional_properties.items():
                _dict[_key] = _value

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "job_id": obj.get("job_id"),
            "graph_id": obj.get("graph_id"),
            "snapshot_date": obj.get("snapshot_date"),
            "status": obj.get("status"),
            "stage": obj.get("stage"),
            "started_at": obj.get("started_at"),
            "finished_at": obj.get("finished_at"),
            "heartbeat_at": obj.get("heartbeat_at"),
            "documents_seen": obj.get("documents_seen"),
            "documents_transformed": obj.get("documents_transformed"),
            "triple_rows_written": obj.get("triple_rows_written"),
            "issues_written": obj.get("issues_written"),
            "retry_count": obj.get("retry_count"),
            "error_code": obj.get("error_code"),
            "error_message": obj.get("error_message"),
            "account_dataset_id": obj.get("account_dataset_id"),
            "website_url": obj.get("website_url"),
            "stage_timings_json": obj.get("stage_timings_json"),
            "runtime_profile_json": obj.get("runtime_profile_json")
        })
        # store additional fields in additional_properties
        for _key in obj.keys():
            if _key not in cls.__properties:
                _obj.additional_properties[_key] = obj.get(_key)

        return _obj


