# 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 pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kubeflow_spark_api.models.spark_v1alpha1_dynamic_allocation import SparkV1alpha1DynamicAllocation
from kubeflow_spark_api.models.spark_v1alpha1_executor_spec import SparkV1alpha1ExecutorSpec
from kubeflow_spark_api.models.spark_v1alpha1_server_spec import SparkV1alpha1ServerSpec
from typing import Optional, Set
from typing_extensions import Self

class SparkV1alpha1SparkConnectSpec(BaseModel):
    """
    SparkConnectSpec defines the desired state of SparkConnect.
    """ # noqa: E501
    dynamic_allocation: Optional[SparkV1alpha1DynamicAllocation] = Field(default=None, description="DynamicAllocation configures dynamic allocation that becomes available for the Kubernetes scheduler backend since Spark 3.0.", alias="dynamicAllocation")
    executor: SparkV1alpha1ExecutorSpec = Field(description="Executor is the Spark executor specification.")
    hadoop_conf: Optional[Dict[str, StrictStr]] = Field(default=None, description="HadoopConf carries user-specified Hadoop configuration properties as they would use the \"--conf\" option in spark-submit. The SparkApplication controller automatically adds prefix \"spark.hadoop.\" to Hadoop configuration properties.", alias="hadoopConf")
    image: Optional[StrictStr] = Field(default=None, description="Image is the container image for the driver, executor, and init-container. Any custom container images for the driver, executor, or init-container takes precedence over this.")
    server: SparkV1alpha1ServerSpec = Field(description="Server is the Spark connect server specification.")
    spark_conf: Optional[Dict[str, StrictStr]] = Field(default=None, description="SparkConf carries user-specified Spark configuration properties as they would use the \"--conf\" option in spark-submit.", alias="sparkConf")
    spark_version: StrictStr = Field(description="SparkVersion is the version of Spark the spark connect use.", alias="sparkVersion")
    __properties: ClassVar[List[str]] = ["dynamicAllocation", "executor", "hadoopConf", "image", "server", "sparkConf", "sparkVersion"]

    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 SparkV1alpha1SparkConnectSpec 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 dynamic_allocation
        if self.dynamic_allocation:
            _dict['dynamicAllocation'] = self.dynamic_allocation.to_dict()
        # override the default output from pydantic by calling `to_dict()` of executor
        if self.executor:
            _dict['executor'] = self.executor.to_dict()
        # override the default output from pydantic by calling `to_dict()` of server
        if self.server:
            _dict['server'] = self.server.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "dynamicAllocation": SparkV1alpha1DynamicAllocation.from_dict(obj["dynamicAllocation"]) if obj.get("dynamicAllocation") is not None else None,
            "executor": SparkV1alpha1ExecutorSpec.from_dict(obj["executor"]) if obj.get("executor") is not None else None,
            "hadoopConf": obj.get("hadoopConf"),
            "image": obj.get("image"),
            "server": SparkV1alpha1ServerSpec.from_dict(obj["server"]) if obj.get("server") is not None else None,
            "sparkConf": obj.get("sparkConf"),
            "sparkVersion": obj.get("sparkVersion") if obj.get("sparkVersion") is not None else ''
        })
        return _obj


