# coding: utf-8

"""
    Graphiant APIs

    Graphiant API documentation.

    The version of the OpenAPI document: 1.0.0
    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 typing_extensions import Annotated
from graphiant_sdk.models.v1_devices_device_id_config_put_request_core_core_vrf_dhcp_subnets_value_subnet_ip_ranges_v2 import V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetIpRangesV2
from graphiant_sdk.models.v1_devices_device_id_config_put_request_core_core_vrf_dhcp_subnets_value_subnet_static_leases_value import V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetStaticLeasesValue
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_branches_excluded_devices_inner_segments_inner_dhcp_subnets_inner_nameservers import V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerNameservers
from graphiant_sdk.models.v1_extranets_get200_response_policies_inner_branches_excluded_devices_inner_segments_inner_dhcp_subnets_inner_ranges_inner import V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerRangesInner
from typing import Optional, Set
from typing_extensions import Self

class V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnet(BaseModel):
    """
    V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnet
    """ # noqa: E501
    default_lease_time_secs: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="defaultLeaseTimeSecs")
    description: Optional[StrictStr] = None
    domain_name: Optional[StrictStr] = Field(default=None, alias="domainName")
    domain_name_server: Optional[V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerNameservers] = Field(default=None, alias="domainNameServer")
    interface: Optional[StrictStr] = None
    ip_gateway: Optional[StrictStr] = Field(default=None, alias="ipGateway")
    ip_prefix: Optional[StrictStr] = Field(default=None, alias="ipPrefix")
    ip_ranges: Optional[List[V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerRangesInner]] = Field(default=None, alias="ipRanges")
    ip_ranges_v2: Optional[V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetIpRangesV2] = Field(default=None, alias="ipRangesV2")
    max_lease_time_secs: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="maxLeaseTimeSecs")
    min_lease_time_secs: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="minLeaseTimeSecs")
    name: Optional[StrictStr] = None
    static_leases: Optional[Dict[str, V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetStaticLeasesValue]] = Field(default=None, alias="staticLeases")
    __properties: ClassVar[List[str]] = ["defaultLeaseTimeSecs", "description", "domainName", "domainNameServer", "interface", "ipGateway", "ipPrefix", "ipRanges", "ipRangesV2", "maxLeaseTimeSecs", "minLeaseTimeSecs", "name", "staticLeases"]

    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 V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnet 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 domain_name_server
        if self.domain_name_server:
            _dict['domainNameServer'] = self.domain_name_server.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in ip_ranges (list)
        _items = []
        if self.ip_ranges:
            for _item_ip_ranges in self.ip_ranges:
                if _item_ip_ranges:
                    _items.append(_item_ip_ranges.to_dict())
            _dict['ipRanges'] = _items
        # override the default output from pydantic by calling `to_dict()` of ip_ranges_v2
        if self.ip_ranges_v2:
            _dict['ipRangesV2'] = self.ip_ranges_v2.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in static_leases (dict)
        _field_dict = {}
        if self.static_leases:
            for _key_static_leases in self.static_leases:
                if self.static_leases[_key_static_leases]:
                    _field_dict[_key_static_leases] = self.static_leases[_key_static_leases].to_dict()
            _dict['staticLeases'] = _field_dict
        return _dict

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

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

        _obj = cls.model_validate({
            "defaultLeaseTimeSecs": obj.get("defaultLeaseTimeSecs"),
            "description": obj.get("description"),
            "domainName": obj.get("domainName"),
            "domainNameServer": V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerNameservers.from_dict(obj["domainNameServer"]) if obj.get("domainNameServer") is not None else None,
            "interface": obj.get("interface"),
            "ipGateway": obj.get("ipGateway"),
            "ipPrefix": obj.get("ipPrefix"),
            "ipRanges": [V1ExtranetsGet200ResponsePoliciesInnerBranchesExcludedDevicesInnerSegmentsInnerDhcpSubnetsInnerRangesInner.from_dict(_item) for _item in obj["ipRanges"]] if obj.get("ipRanges") is not None else None,
            "ipRangesV2": V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetIpRangesV2.from_dict(obj["ipRangesV2"]) if obj.get("ipRangesV2") is not None else None,
            "maxLeaseTimeSecs": obj.get("maxLeaseTimeSecs"),
            "minLeaseTimeSecs": obj.get("minLeaseTimeSecs"),
            "name": obj.get("name"),
            "staticLeases": dict(
                (_k, V1DevicesDeviceIdConfigPutRequestCoreCoreVrfDhcpSubnetsValueSubnetStaticLeasesValue.from_dict(_v))
                for _k, _v in obj["staticLeases"].items()
            )
            if obj.get("staticLeases") is not None
            else None
        })
        return _obj


