# coding: utf-8

"""
    kameleo-local-api

    You can use the following API endpoints to communicate with the local running Kameleo programmatically.

    The version of the OpenAPI document: 4.2.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List
from kameleo.local_api_client.models.profile_preview import ProfilePreview
from kameleo.local_api_client.models.share_access import ShareAccess
from typing import Optional, Set
from typing_extensions import Self

class FolderResponse(BaseModel):
    """
    FolderResponse
    """ # noqa: E501
    id: StrictStr = Field(description="A unique identifier of the folder.")
    name: StrictStr = Field(description="The name of the folder.")
    last_modified_at: datetime = Field(description="Timestamp of the last modification.", alias="lastModifiedAt")
    last_modified_by: StrictStr = Field(description="Name of the user who last modified the folder.", alias="lastModifiedBy")
    created_at: datetime = Field(description="Timestamp of the creation.", alias="createdAt")
    created_by: StrictStr = Field(description="Name of the user who created the folder.", alias="createdBy")
    profiles: List[ProfilePreview] = Field(description="List of profiles in the current folder.")
    share_accesses: List[ShareAccess] = Field(description="List of users accessing this folder.", alias="shareAccesses")
    __properties: ClassVar[List[str]] = ["id", "name", "lastModifiedAt", "lastModifiedBy", "createdAt", "createdBy", "profiles", "shareAccesses"]

    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 FolderResponse 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 profiles (list)
        _items = []
        if self.profiles:
            for _item_profiles in self.profiles:
                if _item_profiles:
                    _items.append(_item_profiles.to_dict())
            _dict['profiles'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in share_accesses (list)
        _items = []
        if self.share_accesses:
            for _item_share_accesses in self.share_accesses:
                if _item_share_accesses:
                    _items.append(_item_share_accesses.to_dict())
            _dict['shareAccesses'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "name": obj.get("name"),
            "lastModifiedAt": obj.get("lastModifiedAt"),
            "lastModifiedBy": obj.get("lastModifiedBy"),
            "createdAt": obj.get("createdAt"),
            "createdBy": obj.get("createdBy"),
            "profiles": [ProfilePreview.from_dict(_item) for _item in obj["profiles"]] if obj.get("profiles") is not None else None,
            "shareAccesses": [ShareAccess.from_dict(_item) for _item in obj["shareAccesses"]] if obj.get("shareAccesses") is not None else None
        })
        return _obj


