# coding: utf-8

"""
    Kubeflow Spark Operator OpenAPI Spec

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

    The version of the OpenAPI document: unversioned
    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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kubeflow_spark_api.models.spark_v1beta2_application_state import SparkV1beta2ApplicationState
from kubeflow_spark_api.models.spark_v1beta2_driver_info import SparkV1beta2DriverInfo
from typing import Optional, Set
from typing_extensions import Self

class SparkV1beta2SparkApplicationStatus(BaseModel):
    """
    SparkApplicationStatus defines the observed state of SparkApplication
    """ # noqa: E501
    application_state: Optional[SparkV1beta2ApplicationState] = Field(default=None, description="AppState tells the overall application state.", alias="applicationState")
    driver_info: SparkV1beta2DriverInfo = Field(description="DriverInfo has information about the driver.", alias="driverInfo")
    execution_attempts: Optional[StrictInt] = Field(default=None, description="ExecutionAttempts is the total number of attempts to run a submitted application to completion. Incremented upon each attempted run of the application and reset upon invalidation.", alias="executionAttempts")
    executor_state: Optional[Dict[str, StrictStr]] = Field(default=None, description="ExecutorState records the state of executors by executor Pod names.", alias="executorState")
    last_submission_attempt_time: Optional[datetime] = Field(default=None, description="LastSubmissionAttemptTime is the time for the last application submission attempt.", alias="lastSubmissionAttemptTime")
    spark_application_id: Optional[StrictStr] = Field(default=None, description="SparkApplicationID is set by the spark-distribution(via spark.app.id config) on the driver and executor pods", alias="sparkApplicationId")
    submission_attempts: Optional[StrictInt] = Field(default=None, description="SubmissionAttempts is the total number of attempts to submit an application to run. Incremented upon each attempted submission of the application and reset upon invalidation and rerun.", alias="submissionAttempts")
    submission_id: Optional[StrictStr] = Field(default=None, description="SubmissionID is a unique ID of the current submission of the application.", alias="submissionID")
    termination_time: Optional[datetime] = Field(default=None, description="CompletionTime is the time when the application runs to completion if it does.", alias="terminationTime")
    __properties: ClassVar[List[str]] = ["applicationState", "driverInfo", "executionAttempts", "executorState", "lastSubmissionAttemptTime", "sparkApplicationId", "submissionAttempts", "submissionID", "terminationTime"]

    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 SparkV1beta2SparkApplicationStatus 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,
        )
        # override the default output from pydantic by calling `to_dict()` of application_state
        if self.application_state:
            _dict['applicationState'] = self.application_state.to_dict()
        # override the default output from pydantic by calling `to_dict()` of driver_info
        if self.driver_info:
            _dict['driverInfo'] = self.driver_info.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "applicationState": SparkV1beta2ApplicationState.from_dict(obj["applicationState"]) if obj.get("applicationState") is not None else None,
            "driverInfo": SparkV1beta2DriverInfo.from_dict(obj["driverInfo"]) if obj.get("driverInfo") is not None else None,
            "executionAttempts": obj.get("executionAttempts"),
            "executorState": obj.get("executorState"),
            "lastSubmissionAttemptTime": obj.get("lastSubmissionAttemptTime"),
            "sparkApplicationId": obj.get("sparkApplicationId"),
            "submissionAttempts": obj.get("submissionAttempts"),
            "submissionID": obj.get("submissionID"),
            "terminationTime": obj.get("terminationTime")
        })
        return _obj


