# 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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from kubeflow_spark_api.models.io_k8s_api_networking_v1_ingress_tls import IoK8sApiNetworkingV1IngressTLS
from typing import Optional, Set
from typing_extensions import Self

class SparkV1beta2SparkUIConfiguration(BaseModel):
    """
    SparkUIConfiguration is for driver UI specific configuration parameters.
    """ # noqa: E501
    ingress_annotations: Optional[Dict[str, StrictStr]] = Field(default=None, description="IngressAnnotations is a map of key,value pairs of annotations that might be added to the ingress object. i.e. specify nginx as ingress.class", alias="ingressAnnotations")
    ingress_tls: Optional[List[IoK8sApiNetworkingV1IngressTLS]] = Field(default=None, description="TlsHosts is useful If we need to declare SSL certificates to the ingress object", alias="ingressTLS")
    service_annotations: Optional[Dict[str, StrictStr]] = Field(default=None, description="ServiceAnnotations is a map of key,value pairs of annotations that might be added to the service object.", alias="serviceAnnotations")
    service_labels: Optional[Dict[str, StrictStr]] = Field(default=None, description="ServiceLabels is a map of key,value pairs of labels that might be added to the service object.", alias="serviceLabels")
    service_port: Optional[StrictInt] = Field(default=None, description="ServicePort allows configuring the port at service level that might be different from the targetPort. TargetPort should be the same as the one defined in spark.ui.port", alias="servicePort")
    service_port_name: Optional[StrictStr] = Field(default=None, description="ServicePortName allows configuring the name of the service port. This may be useful for sidecar proxies like Envoy injected by Istio which require specific ports names to treat traffic as proper HTTP. Defaults to spark-driver-ui-port.", alias="servicePortName")
    service_type: Optional[StrictStr] = Field(default=None, description="ServiceType allows configuring the type of the service. Defaults to ClusterIP.  Possible enum values:  - `\"ClusterIP\"` means a service will only be accessible inside the cluster, via the cluster IP.  - `\"ExternalName\"` means a service consists of only a reference to an external name that kubedns or equivalent will return as a CNAME record, with no exposing or proxying of any pods involved.  - `\"LoadBalancer\"` means a service will be exposed via an external load balancer (if the cloud provider supports it), in addition to 'NodePort' type.  - `\"NodePort\"` means a service will be exposed on one port of every node, in addition to 'ClusterIP' type.", alias="serviceType")
    __properties: ClassVar[List[str]] = ["ingressAnnotations", "ingressTLS", "serviceAnnotations", "serviceLabels", "servicePort", "servicePortName", "serviceType"]

    @field_validator('service_type')
    def service_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['ClusterIP', 'ExternalName', 'LoadBalancer', 'NodePort']):
            raise ValueError("must be one of enum values ('ClusterIP', 'ExternalName', 'LoadBalancer', 'NodePort')")
        return value

    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 SparkV1beta2SparkUIConfiguration 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 each item in ingress_tls (list)
        _items = []
        if self.ingress_tls:
            for _item_ingress_tls in self.ingress_tls:
                if _item_ingress_tls:
                    _items.append(_item_ingress_tls.to_dict())
            _dict['ingressTLS'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "ingressAnnotations": obj.get("ingressAnnotations"),
            "ingressTLS": [IoK8sApiNetworkingV1IngressTLS.from_dict(_item) for _item in obj["ingressTLS"]] if obj.get("ingressTLS") is not None else None,
            "serviceAnnotations": obj.get("serviceAnnotations"),
            "serviceLabels": obj.get("serviceLabels"),
            "servicePort": obj.get("servicePort"),
            "servicePortName": obj.get("servicePortName"),
            "serviceType": obj.get("serviceType")
        })
        return _obj


