# coding: utf-8

"""
    Artifact Keeper API

    REST API for Artifact Keeper, an open-source universal artifact registry. Covers user management, repositories, artifacts, search, security scanning, SBOM, dependency tracking, SSO, analytics, monitoring, telemetry, lifecycle policies, plugins, edge nodes, migration, and administration. Format-specific protocol endpoints (npm, PyPI, Maven, Docker/OCI, etc.) are not included; those follow their respective upstream specifications.

    The version of the OpenAPI document: 1.0.0-a2
    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 typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class CreateLdapConfigRequest(BaseModel):
    """
    CreateLdapConfigRequest
    """ # noqa: E501
    name: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Display name for the LDAP provider")
    server_url: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP server URL (ldap:// or ldaps://)")
    bind_dn: Optional[StrictStr] = Field(default=None, description="Distinguished name used for binding to the LDAP server")
    bind_password: Optional[StrictStr] = Field(default=None, description="Password for the bind DN")
    user_base_dn: Annotated[str, Field(min_length=1, strict=True)] = Field(description="Base DN for user searches")
    user_filter: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP filter for user lookups")
    group_base_dn: Optional[StrictStr] = Field(default=None, description="Base DN for group searches")
    group_filter: Optional[StrictStr] = Field(default=None, description="LDAP filter for group lookups")
    email_attribute: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP attribute containing the user email")
    display_name_attribute: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP attribute containing the user display name")
    username_attribute: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP attribute containing the username")
    groups_attribute: Annotated[str, Field(min_length=1, strict=True)] = Field(description="LDAP attribute containing group membership")
    admin_group_dn: Optional[StrictStr] = Field(default=None, description="DN of the group whose members are granted admin privileges")
    use_starttls: Optional[StrictBool] = Field(default=False, description="Whether to use STARTTLS for the LDAP connection")
    is_enabled: Optional[StrictBool] = Field(default=False, description="Whether to enable the configuration immediately")
    __properties: ClassVar[List[str]] = ["name", "server_url", "bind_dn", "bind_password", "user_base_dn", "user_filter", "group_base_dn", "group_filter", "email_attribute", "display_name_attribute", "username_attribute", "groups_attribute", "admin_group_dn", "use_starttls", "is_enabled"]

    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 CreateLdapConfigRequest 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "server_url": obj.get("server_url"),
            "bind_dn": obj.get("bind_dn"),
            "bind_password": obj.get("bind_password"),
            "user_base_dn": obj.get("user_base_dn"),
            "user_filter": obj.get("user_filter"),
            "group_base_dn": obj.get("group_base_dn"),
            "group_filter": obj.get("group_filter"),
            "email_attribute": obj.get("email_attribute"),
            "display_name_attribute": obj.get("display_name_attribute"),
            "username_attribute": obj.get("username_attribute"),
            "groups_attribute": obj.get("groups_attribute"),
            "admin_group_dn": obj.get("admin_group_dn"),
            "use_starttls": obj.get("use_starttls") if obj.get("use_starttls") is not None else False,
            "is_enabled": obj.get("is_enabled") if obj.get("is_enabled") is not None else False
        })
        return _obj


