# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2026.5.0-rc1
    Contact: hello@goauthentik.io
    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
from typing import Any, ClassVar, Dict, List, Optional
from authentik_client.models.device_group_request import DeviceGroupRequest
from authentik_client.models.device_user_request import DeviceUserRequest
from authentik_client.models.disk_request import DiskRequest
from authentik_client.models.hardware_request import HardwareRequest
from authentik_client.models.network_request import NetworkRequest
from authentik_client.models.operating_system_request import OperatingSystemRequest
from authentik_client.models.process_request import ProcessRequest
from authentik_client.models.software_request import SoftwareRequest
from typing import Optional, Set
from typing_extensions import Self

class DeviceFactsRequest(BaseModel):
    """
    DeviceFactsRequest
    """ # noqa: E501
    os: Optional[OperatingSystemRequest] = None
    disks: Optional[List[DiskRequest]] = None
    network: Optional[NetworkRequest] = None
    hardware: Optional[HardwareRequest] = None
    software: Optional[List[SoftwareRequest]] = None
    processes: Optional[List[ProcessRequest]] = None
    users: Optional[List[DeviceUserRequest]] = None
    groups: Optional[List[DeviceGroupRequest]] = None
    vendor: Optional[Dict[str, Any]] = None
    __properties: ClassVar[List[str]] = ["os", "disks", "network", "hardware", "software", "processes", "users", "groups", "vendor"]

    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 DeviceFactsRequest 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 os
        if self.os:
            _dict['os'] = self.os.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in disks (list)
        _items = []
        if self.disks:
            for _item_disks in self.disks:
                if _item_disks:
                    _items.append(_item_disks.to_dict())
            _dict['disks'] = _items
        # override the default output from pydantic by calling `to_dict()` of network
        if self.network:
            _dict['network'] = self.network.to_dict()
        # override the default output from pydantic by calling `to_dict()` of hardware
        if self.hardware:
            _dict['hardware'] = self.hardware.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in software (list)
        _items = []
        if self.software:
            for _item_software in self.software:
                if _item_software:
                    _items.append(_item_software.to_dict())
            _dict['software'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in processes (list)
        _items = []
        if self.processes:
            for _item_processes in self.processes:
                if _item_processes:
                    _items.append(_item_processes.to_dict())
            _dict['processes'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in users (list)
        _items = []
        if self.users:
            for _item_users in self.users:
                if _item_users:
                    _items.append(_item_users.to_dict())
            _dict['users'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in groups (list)
        _items = []
        if self.groups:
            for _item_groups in self.groups:
                if _item_groups:
                    _items.append(_item_groups.to_dict())
            _dict['groups'] = _items
        # set to None if os (nullable) is None
        # and model_fields_set contains the field
        if self.os is None and "os" in self.model_fields_set:
            _dict['os'] = None

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "os": OperatingSystemRequest.from_dict(obj["os"]) if obj.get("os") is not None else None,
            "disks": [DiskRequest.from_dict(_item) for _item in obj["disks"]] if obj.get("disks") is not None else None,
            "network": NetworkRequest.from_dict(obj["network"]) if obj.get("network") is not None else None,
            "hardware": HardwareRequest.from_dict(obj["hardware"]) if obj.get("hardware") is not None else None,
            "software": [SoftwareRequest.from_dict(_item) for _item in obj["software"]] if obj.get("software") is not None else None,
            "processes": [ProcessRequest.from_dict(_item) for _item in obj["processes"]] if obj.get("processes") is not None else None,
            "users": [DeviceUserRequest.from_dict(_item) for _item in obj["users"]] if obj.get("users") is not None else None,
            "groups": [DeviceGroupRequest.from_dict(_item) for _item in obj["groups"]] if obj.get("groups") is not None else None,
            "vendor": obj.get("vendor")
        })
        return _obj


