# coding: utf-8

"""
Earnix Elevate Data API

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

The version of the OpenAPI document: 0.0.1
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""

from __future__ import annotations

import json
import pprint
from datetime import datetime
from typing import Optional

from pydantic.v1 import BaseModel, Field, StrictBool

from earnix_elevate.clients.data.models.job_execution import JobExecution
from earnix_elevate.clients.data.models.metadata import Metadata
from earnix_elevate.clients.data.models.user import User


class RecipeStatusResponse(BaseModel):
    """
    `RecipeStatusResponse`

    Represents the current execution status of a recipe node within a transformation graph
    """

    start_time: Optional[datetime] = Field(
        default=None,
        alias="startTime",
        description="Date and time when the recipe execution started, null if not yet started",
    )
    end_time: Optional[datetime] = Field(
        default=None,
        alias="endTime",
        description="Date and time when the recipe execution completed, null if still running or not started",
    )
    use_sample: Optional[StrictBool] = Field(
        default=None,
        alias="useSample",
        description="Whether the recipe was executed on a sample of the data instead of the complete dataset",
    )
    last_run: Optional[datetime] = Field(
        default=None,
        alias="lastRun",
        description="Date and time when this entity was created",
    )
    run_by: Optional[User] = Field(default=None, alias="runBy")
    metadata: Optional[Metadata] = None
    execution: Optional[JobExecution] = None
    __properties = [
        "startTime",
        "endTime",
        "useSample",
        "lastRun",
        "runBy",
        "metadata",
        "execution",
    ]

    class Config:
        """Pydantic configuration"""

        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> RecipeStatusResponse:
        """Create an instance of RecipeStatusResponse from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True, exclude={}, exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of run_by
        if self.run_by:
            _dict["runBy"] = self.run_by.to_dict()
        # override the default output from pydantic by calling `to_dict()` of metadata
        if self.metadata:
            _dict["metadata"] = self.metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of execution
        if self.execution:
            _dict["execution"] = self.execution.to_dict()
        # set to None if start_time (nullable) is None
        # and __fields_set__ contains the field
        if self.start_time is None and "start_time" in self.__fields_set__:
            _dict["startTime"] = None

        # set to None if end_time (nullable) is None
        # and __fields_set__ contains the field
        if self.end_time is None and "end_time" in self.__fields_set__:
            _dict["endTime"] = None

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> RecipeStatusResponse:
        """Create an instance of RecipeStatusResponse from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return RecipeStatusResponse.parse_obj(obj)

        _obj = RecipeStatusResponse.parse_obj(
            {
                "start_time": obj.get("startTime"),
                "end_time": obj.get("endTime"),
                "use_sample": obj.get("useSample"),
                "last_run": obj.get("lastRun"),
                "run_by": User.from_dict(obj.get("runBy"))
                if obj.get("runBy") is not None
                else None,
                "metadata": Metadata.from_dict(obj.get("metadata"))
                if obj.get("metadata") is not None
                else None,
                "execution": JobExecution.from_dict(obj.get("execution"))
                if obj.get("execution") is not None
                else None,
            }
        )
        return _obj
