# coding: utf-8

"""
    Kubernetes

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

    The version of the OpenAPI document: release-1.29
    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 typing import List, Optional
from pydantic import BaseModel, Field, StrictStr, conlist
from .v1_port_status import V1PortStatus

class V1LoadBalancerIngress(BaseModel):
    """
    LoadBalancerIngress represents the status of a load-balancer ingress point: traffic intended for the service should be sent to an ingress point.  # noqa: E501
    """
    hostname: Optional[StrictStr] = Field(None, description="Hostname is set for load-balancer ingress points that are DNS based (typically AWS load-balancers)")
    ip: Optional[StrictStr] = Field(None, description="IP is set for load-balancer ingress points that are IP based (typically GCE or OpenStack load-balancers)")
    ip_mode: Optional[StrictStr] = Field(None, alias="ipMode", description="IPMode specifies how the load-balancer IP behaves, and may only be specified when the ip field is specified. Setting this to \"VIP\" indicates that traffic is delivered to the node with the destination set to the load-balancer's IP and port. Setting this to \"Proxy\" indicates that traffic is delivered to the node or pod with the destination set to the node's IP and node port or the pod's IP and port. Service implementations may use this information to adjust traffic routing.")
    ports: Optional[conlist(V1PortStatus)] = Field(None, description="Ports is a list of records of service ports If used, every port defined in the service should have an entry in it")
    __properties = ["hostname", "ip", "ipMode", "ports"]

    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) -> V1LoadBalancerIngress:
        """Create an instance of V1LoadBalancerIngress 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 each item in ports (list)
        _items = []
        if self.ports:
            for _item in self.ports:
                if _item:
                    _items.append(_item.to_dict())
            _dict['ports'] = _items
        return _dict

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

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

        _obj = V1LoadBalancerIngress.parse_obj({
            "hostname": obj.get("hostname"),
            "ip": obj.get("ip"),
            "ip_mode": obj.get("ipMode"),
            "ports": [V1PortStatus.from_dict(_item) for _item in obj.get("ports")] if obj.get("ports") is not None else None
        })
        return _obj


