# coding: utf-8

"""
    FlowHunt

    FlowHunt API

    The version of the OpenAPI document: 2.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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from flowhunt.models.saml_login_method import SamlLoginMethod
from typing import Optional, Set
from typing_extensions import Self

class WorkspaceSSOUpdateRequest(BaseModel):
    """
    Request DTO for updating workspace SSO settings.
    """ # noqa: E501
    enabled: Optional[StrictBool] = Field(default=True, description="Whether SSO is enabled")
    idp_sso_url: Optional[StrictStr] = None
    idp_entity_id: Optional[StrictStr] = None
    idp_x509_cert: Optional[StrictStr] = None
    jit_provisioning_enabled: Optional[StrictBool] = Field(default=False, description="Enable Just-In-Time user provisioning")
    email_attribute: Optional[StrictStr] = None
    name_id_format: Optional[StrictStr] = None
    first_name_attribute: Optional[StrictStr] = None
    last_name_attribute: Optional[StrictStr] = None
    role_attribute: Optional[StrictStr] = None
    login_method: Optional[SamlLoginMethod] = None
    idp_metadata_xml: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["enabled", "idp_sso_url", "idp_entity_id", "idp_x509_cert", "jit_provisioning_enabled", "email_attribute", "name_id_format", "first_name_attribute", "last_name_attribute", "role_attribute", "login_method", "idp_metadata_xml"]

    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 WorkspaceSSOUpdateRequest 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,
        )
        # set to None if idp_sso_url (nullable) is None
        # and model_fields_set contains the field
        if self.idp_sso_url is None and "idp_sso_url" in self.model_fields_set:
            _dict['idp_sso_url'] = None

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "enabled": obj.get("enabled") if obj.get("enabled") is not None else True,
            "idp_sso_url": obj.get("idp_sso_url"),
            "idp_entity_id": obj.get("idp_entity_id"),
            "idp_x509_cert": obj.get("idp_x509_cert"),
            "jit_provisioning_enabled": obj.get("jit_provisioning_enabled") if obj.get("jit_provisioning_enabled") is not None else False,
            "email_attribute": obj.get("email_attribute"),
            "name_id_format": obj.get("name_id_format"),
            "first_name_attribute": obj.get("first_name_attribute"),
            "last_name_attribute": obj.get("last_name_attribute"),
            "role_attribute": obj.get("role_attribute"),
            "login_method": obj.get("login_method"),
            "idp_metadata_xml": obj.get("idp_metadata_xml")
        })
        return _obj


