# coding: utf-8

"""
    Torizon OTA

     This API is rate limited and will return the following headers for each API call.    - X-RateLimit-Limit - The total number of requests allowed within a time period   - X-RateLimit-Remaining - The total number of requests still allowed until the end of the rate limiting period   - X-RateLimit-Reset - The number of seconds until the limit is fully reset  In addition, if an API client is rate limited, it will receive a HTTP 420 response with the following header:     - Retry-After - The number of seconds to wait until this request is allowed  

    The version of the OpenAPI document: 2.0-Beta
    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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from torizon_io_api.models.device_package import DevicePackage
from torizon_io_api.models.device_status import DeviceStatus
from torizon_io_api.models.fleet import Fleet
from torizon_io_api.models.network_info import NetworkInfo
from torizon_io_api.models.tuple2_device_tag_id_device_tag_value import Tuple2DeviceTagIdDeviceTagValue
from typing import Optional, Set
from typing_extensions import Self

class DeviceInfoExtended(BaseModel):
    """
    DeviceInfoExtended
    """ # noqa: E501
    device_uuid: StrictStr = Field(alias="deviceUuid")
    device_name: StrictStr = Field(alias="deviceName")
    device_id: StrictStr = Field(alias="deviceId")
    last_seen: Optional[datetime] = Field(default=None, alias="lastSeen")
    created_at: datetime = Field(alias="createdAt")
    activated_at: Optional[datetime] = Field(default=None, alias="activatedAt")
    device_status: DeviceStatus = Field(alias="deviceStatus")
    notes: Optional[StrictStr] = None
    hibernated: StrictBool
    last_updated: Optional[datetime] = Field(default=None, alias="lastUpdated")
    device_fleets: Optional[List[Fleet]] = Field(default=None, alias="deviceFleets")
    device_packages: Optional[List[DevicePackage]] = Field(default=None, alias="devicePackages")
    device_tags: Optional[List[Tuple2DeviceTagIdDeviceTagValue]] = Field(default=None, alias="deviceTags")
    network_info: NetworkInfo = Field(alias="networkInfo")
    __properties: ClassVar[List[str]] = ["deviceUuid", "deviceName", "deviceId", "lastSeen", "createdAt", "activatedAt", "deviceStatus", "notes", "hibernated", "lastUpdated", "deviceFleets", "devicePackages", "deviceTags", "networkInfo"]

    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 DeviceInfoExtended 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 device_fleets (list)
        _items = []
        if self.device_fleets:
            for _item_device_fleets in self.device_fleets:
                if _item_device_fleets:
                    _items.append(_item_device_fleets.to_dict())
            _dict['deviceFleets'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in device_packages (list)
        _items = []
        if self.device_packages:
            for _item_device_packages in self.device_packages:
                if _item_device_packages:
                    _items.append(_item_device_packages.to_dict())
            _dict['devicePackages'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in device_tags (list)
        _items = []
        if self.device_tags:
            for _item_device_tags in self.device_tags:
                if _item_device_tags:
                    _items.append(_item_device_tags.to_dict())
            _dict['deviceTags'] = _items
        # override the default output from pydantic by calling `to_dict()` of network_info
        if self.network_info:
            _dict['networkInfo'] = self.network_info.to_dict()
        # set to None if last_seen (nullable) is None
        # and model_fields_set contains the field
        if self.last_seen is None and "last_seen" in self.model_fields_set:
            _dict['lastSeen'] = None

        # set to None if activated_at (nullable) is None
        # and model_fields_set contains the field
        if self.activated_at is None and "activated_at" in self.model_fields_set:
            _dict['activatedAt'] = None

        # set to None if notes (nullable) is None
        # and model_fields_set contains the field
        if self.notes is None and "notes" in self.model_fields_set:
            _dict['notes'] = None

        # set to None if last_updated (nullable) is None
        # and model_fields_set contains the field
        if self.last_updated is None and "last_updated" in self.model_fields_set:
            _dict['lastUpdated'] = None

        return _dict

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

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

        _obj = cls.model_validate({
            "deviceUuid": obj.get("deviceUuid"),
            "deviceName": obj.get("deviceName"),
            "deviceId": obj.get("deviceId"),
            "lastSeen": obj.get("lastSeen"),
            "createdAt": obj.get("createdAt"),
            "activatedAt": obj.get("activatedAt"),
            "deviceStatus": obj.get("deviceStatus"),
            "notes": obj.get("notes"),
            "hibernated": obj.get("hibernated"),
            "lastUpdated": obj.get("lastUpdated"),
            "deviceFleets": [Fleet.from_dict(_item) for _item in obj["deviceFleets"]] if obj.get("deviceFleets") is not None else None,
            "devicePackages": [DevicePackage.from_dict(_item) for _item in obj["devicePackages"]] if obj.get("devicePackages") is not None else None,
            "deviceTags": [Tuple2DeviceTagIdDeviceTagValue.from_dict(_item) for _item in obj["deviceTags"]] if obj.get("deviceTags") is not None else None,
            "networkInfo": NetworkInfo.from_dict(obj["networkInfo"]) if obj.get("networkInfo") is not None else None
        })
        return _obj


