# coding: utf-8

"""
    authentik

    Making authentication simple.

    The version of the OpenAPI document: 2026.2.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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from authentik_client.models.config import Config
from authentik_client.models.license_status_enum import LicenseStatusEnum
from typing import Optional, Set
from typing_extensions import Self

class AgentConfig(BaseModel):
    """
    Base serializer class which doesn't implement create/update methods
    """ # noqa: E501
    device_id: StrictStr
    refresh_interval: StrictInt
    authorization_flow: Optional[StrictStr]
    jwks_auth: Dict[str, Any]
    jwks_challenge: Optional[Dict[str, Any]]
    nss_uid_offset: StrictInt
    nss_gid_offset: StrictInt
    auth_terminate_session_on_expiry: StrictBool
    system_config: Config
    license_status: Optional[LicenseStatusEnum]
    __properties: ClassVar[List[str]] = ["device_id", "refresh_interval", "authorization_flow", "jwks_auth", "jwks_challenge", "nss_uid_offset", "nss_gid_offset", "auth_terminate_session_on_expiry", "system_config", "license_status"]

    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 AgentConfig 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "device_id",
            "refresh_interval",
            "authorization_flow",
            "jwks_auth",
            "jwks_challenge",
            "system_config",
            "license_status",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of system_config
        if self.system_config:
            _dict['system_config'] = self.system_config.to_dict()
        # set to None if authorization_flow (nullable) is None
        # and model_fields_set contains the field
        if self.authorization_flow is None and "authorization_flow" in self.model_fields_set:
            _dict['authorization_flow'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "device_id": obj.get("device_id"),
            "refresh_interval": obj.get("refresh_interval"),
            "authorization_flow": obj.get("authorization_flow"),
            "jwks_auth": obj.get("jwks_auth"),
            "jwks_challenge": obj.get("jwks_challenge"),
            "nss_uid_offset": obj.get("nss_uid_offset"),
            "nss_gid_offset": obj.get("nss_gid_offset"),
            "auth_terminate_session_on_expiry": obj.get("auth_terminate_session_on_expiry"),
            "system_config": Config.from_dict(obj["system_config"]) if obj.get("system_config") is not None else None,
            "license_status": obj.get("license_status")
        })
        return _obj


