# coding: utf-8

"""
    Zitadel SDK

    The Zitadel SDK is a convenience wrapper around the Zitadel APIs to assist you in integrating with your Zitadel environment. This SDK enables you to handle resources, settings, and configurations within the Zitadel platform.

    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, StrictBool
from typing import Any, ClassVar, Dict, List, Optional
from zitadel_client.models.feature_service_improved_performance import FeatureServiceImprovedPerformance
from zitadel_client.models.feature_service_login_v2 import FeatureServiceLoginV2
from typing import Optional, Set
from typing_extensions import Self

class FeatureServiceSetSystemFeaturesRequest(BaseModel):
    """
    FeatureServiceSetSystemFeaturesRequest
    """ # noqa: E501
    login_default_org: Optional[StrictBool] = Field(default=None, description="The login UI will use the settings of the default org (and not from the instance) if no organization context is set", alias="loginDefaultOrg")
    oidc_trigger_introspection_projections: Optional[StrictBool] = Field(default=None, description="Enable projection triggers during an introspection request. This can act as workaround if there are noticeable consistency issues in the introspection response but can have an impact on performance. We are planning to remove triggers for introspection requests in the future. Please raise an issue if you needed to enable this feature.", alias="oidcTriggerIntrospectionProjections")
    oidc_legacy_introspection: Optional[StrictBool] = Field(default=None, description="We have recently refactored the introspection endpoint for performance reasons. This feature can be used to rollback to the legacy implementation if unexpected bugs arise. Please raise an issue if you needed to enable this feature.", alias="oidcLegacyIntrospection")
    user_schema: Optional[StrictBool] = Field(default=None, description="User Schemas allow to manage data schemas of user. If the flag is enabled, you'll be able to use the new API and its features. Note that it is still in an early stage.", alias="userSchema")
    oidc_token_exchange: Optional[StrictBool] = Field(default=None, description="Enable the experimental `urn:ietf:params:oauth:grant-type:token-exchange` grant type for the OIDC token endpoint. Token exchange can be used to request tokens with a lesser scope or impersonate other users. See the security policy to allow impersonation on an instance.", alias="oidcTokenExchange")
    improved_performance: Optional[List[FeatureServiceImprovedPerformance]] = Field(default=None, description="Improves performance of specified execution paths.", alias="improvedPerformance")
    oidc_single_v1_session_termination: Optional[StrictBool] = Field(default=None, description="If the flag is enabled, you'll be able to terminate a single session from the login UI by providing an id_token with a `sid` claim as id_token_hint on the end_session endpoint. Note that currently all sessions from the same user agent (browser) are terminated in the login UI. Sessions managed through the Session API already allow the termination of single sessions.", alias="oidcSingleV1SessionTermination")
    disable_user_token_event: Optional[StrictBool] = Field(default=None, description="Do not push user token meta-event user.token.v2.added to improve performance on many concurrent single (machine-)user logins", alias="disableUserTokenEvent")
    enable_back_channel_logout: Optional[StrictBool] = Field(default=None, description="If the flag is enabled, you'll be able to use the OIDC Back-Channel Logout to be notified in your application about terminated user sessions.", alias="enableBackChannelLogout")
    login_v2: Optional[FeatureServiceLoginV2] = Field(default=None, alias="loginV2")
    permission_check_v2: Optional[StrictBool] = Field(default=None, description="Enable a newer, more performant, permission check used for v2 and v3 resource based APIs.", alias="permissionCheckV2")

    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 FeatureServiceSetSystemFeaturesRequest 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 login_v2
        if self.login_v2:
            _dict['loginV2'] = self.login_v2.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "loginDefaultOrg": obj.get("loginDefaultOrg"),
            "oidcTriggerIntrospectionProjections": obj.get("oidcTriggerIntrospectionProjections"),
            "oidcLegacyIntrospection": obj.get("oidcLegacyIntrospection"),
            "userSchema": obj.get("userSchema"),
            "oidcTokenExchange": obj.get("oidcTokenExchange"),
            "improvedPerformance": obj.get("improvedPerformance"),
            "oidcSingleV1SessionTermination": obj.get("oidcSingleV1SessionTermination"),
            "disableUserTokenEvent": obj.get("disableUserTokenEvent"),
            "enableBackChannelLogout": obj.get("enableBackChannelLogout"),
            "loginV2": FeatureServiceLoginV2.from_dict(obj["loginV2"]) if obj.get("loginV2") is not None else None,
            "permissionCheckV2": obj.get("permissionCheckV2")
        })
        return _obj


