# coding: utf-8

"""
    Kanidm

    API for interacting with the Kanidm system. This is a work in progress.

    The version of the OpenAPI document: 1.9.0-dev
    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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from kanidm_openapi_client.models.credential_detail import CredentialDetail
from kanidm_openapi_client.models.cu_cred_state import CUCredState
from kanidm_openapi_client.models.cu_ext_portal import CUExtPortal
from kanidm_openapi_client.models.cu_reg_state import CURegState
from kanidm_openapi_client.models.cu_reg_warning import CURegWarning
from kanidm_openapi_client.models.passkey_detail import PasskeyDetail
from typing import Optional, Set
from typing_extensions import Self

class CUStatus(BaseModel):
    """
    CUStatus
    """ # noqa: E501
    spn: StrictStr
    displayname: StrictStr
    ext_cred_portal: CUExtPortal
    mfaregstate: CURegState
    can_commit: StrictBool
    warnings: List[CURegWarning]
    primary: Optional[CredentialDetail] = None
    primary_state: CUCredState
    passkeys: List[PasskeyDetail]
    passkeys_state: CUCredState
    attested_passkeys: List[PasskeyDetail]
    attested_passkeys_state: CUCredState
    attested_passkeys_allowed_devices: List[StrictStr]
    unixcred: Optional[CredentialDetail] = None
    unixcred_state: CUCredState
    sshkeys: Dict[str, Any]
    sshkeys_state: CUCredState
    __properties: ClassVar[List[str]] = ["spn", "displayname", "ext_cred_portal", "mfaregstate", "can_commit", "warnings", "primary", "primary_state", "passkeys", "passkeys_state", "attested_passkeys", "attested_passkeys_state", "attested_passkeys_allowed_devices", "unixcred", "unixcred_state", "sshkeys", "sshkeys_state"]

    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"""
        return self.model_dump_json(by_alias=True, exclude_unset=True)

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of CUStatus 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 ext_cred_portal
        if self.ext_cred_portal:
            _dict['ext_cred_portal'] = self.ext_cred_portal.to_dict()
        # override the default output from pydantic by calling `to_dict()` of mfaregstate
        if self.mfaregstate:
            _dict['mfaregstate'] = self.mfaregstate.to_dict()
        # override the default output from pydantic by calling `to_dict()` of primary
        if self.primary:
            _dict['primary'] = self.primary.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in passkeys (list)
        _items = []
        if self.passkeys:
            for _item_passkeys in self.passkeys:
                if _item_passkeys:
                    _items.append(_item_passkeys.to_dict())
            _dict['passkeys'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in attested_passkeys (list)
        _items = []
        if self.attested_passkeys:
            for _item_attested_passkeys in self.attested_passkeys:
                if _item_attested_passkeys:
                    _items.append(_item_attested_passkeys.to_dict())
            _dict['attested_passkeys'] = _items
        # override the default output from pydantic by calling `to_dict()` of unixcred
        if self.unixcred:
            _dict['unixcred'] = self.unixcred.to_dict()
        # set to None if primary (nullable) is None
        # and model_fields_set contains the field
        if self.primary is None and "primary" in self.model_fields_set:
            _dict['primary'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "spn": obj.get("spn"),
            "displayname": obj.get("displayname"),
            "ext_cred_portal": CUExtPortal.from_dict(obj["ext_cred_portal"]) if obj.get("ext_cred_portal") is not None else None,
            "mfaregstate": CURegState.from_dict(obj["mfaregstate"]) if obj.get("mfaregstate") is not None else None,
            "can_commit": obj.get("can_commit"),
            "warnings": obj.get("warnings"),
            "primary": CredentialDetail.from_dict(obj["primary"]) if obj.get("primary") is not None else None,
            "primary_state": obj.get("primary_state"),
            "passkeys": [PasskeyDetail.from_dict(_item) for _item in obj["passkeys"]] if obj.get("passkeys") is not None else None,
            "passkeys_state": obj.get("passkeys_state"),
            "attested_passkeys": [PasskeyDetail.from_dict(_item) for _item in obj["attested_passkeys"]] if obj.get("attested_passkeys") is not None else None,
            "attested_passkeys_state": obj.get("attested_passkeys_state"),
            "attested_passkeys_allowed_devices": obj.get("attested_passkeys_allowed_devices"),
            "unixcred": CredentialDetail.from_dict(obj["unixcred"]) if obj.get("unixcred") is not None else None,
            "unixcred_state": obj.get("unixcred_state"),
            "sshkeys": obj.get("sshkeys"),
            "sshkeys_state": obj.get("sshkeys_state")
        })
        return _obj


