# 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, Field, StrictBool
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from kanidm_openapi_client.models.attribute import Attribute
from kanidm_openapi_client.models.scim_sort_order import ScimSortOrder
from typing import Optional, Set
from typing_extensions import Self

class ScimEntryGetQuery(BaseModel):
    """
    SCIM Query Parameters used during the get of a single entry
    """ # noqa: E501
    attributes: Optional[List[Attribute]] = None
    ext_access_check: Optional[StrictBool] = Field(default=None, alias="extAccessCheck")
    sort_by: Optional[Attribute] = Field(default=None, alias="sortBy")
    sort_order: Optional[ScimSortOrder] = Field(default=None, alias="sortOrder")
    start_index: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=None, alias="startIndex")
    count: Optional[Annotated[int, Field(strict=True, ge=0)]] = None
    filter: Optional[Any] = None
    __properties: ClassVar[List[str]] = ["attributes", "extAccessCheck", "sortBy", "sortOrder", "startIndex", "count", "filter"]

    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 ScimEntryGetQuery 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 each item in attributes (list)
        _items = []
        if self.attributes:
            for _item_attributes in self.attributes:
                if _item_attributes:
                    _items.append(_item_attributes.to_dict())
            _dict['attributes'] = _items
        # override the default output from pydantic by calling `to_dict()` of sort_by
        if self.sort_by:
            _dict['sortBy'] = self.sort_by.to_dict()
        # set to None if attributes (nullable) is None
        # and model_fields_set contains the field
        if self.attributes is None and "attributes" in self.model_fields_set:
            _dict['attributes'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "attributes": [Attribute.from_dict(_item) for _item in obj["attributes"]] if obj.get("attributes") is not None else None,
            "extAccessCheck": obj.get("extAccessCheck"),
            "sortBy": Attribute.from_dict(obj["sortBy"]) if obj.get("sortBy") is not None else None,
            "sortOrder": obj.get("sortOrder"),
            "startIndex": obj.get("startIndex"),
            "count": obj.get("count"),
            "filter": obj.get("filter")
        })
        return _obj


