# coding: utf-8

"""
    Ephor.ai

    Collaborative AI

    The version of the OpenAPI document: 1.3.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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from ephor_server_ti_client.models.collection_item import CollectionItem
from ephor_server_ti_client.models.comment import Comment
from typing import Optional, Set
from typing_extensions import Self

class ProjectCreate(BaseModel):
    """
    ProjectCreate
    """ # noqa: E501
    name: StrictStr
    description: Optional[StrictStr] = None
    collection: List[CollectionItem]
    users: Dict[str, StrictStr]
    predefined_queries: Optional[List[StrictStr]] = None
    custom_instructions: Optional[StrictStr] = None
    model: Optional[StrictStr] = None
    comments: Optional[List[Comment]] = None
    updated_at: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["name", "description", "collection", "users", "predefined_queries", "custom_instructions", "model", "comments", "updated_at"]

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ProjectCreate 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"),
            "description": obj.get("description"),
            "collection": [CollectionItem.from_dict(_item) for _item in obj["collection"]] if obj.get("collection") is not None else None,
            "users": obj.get("users"),
            "predefined_queries": obj.get("predefined_queries"),
            "custom_instructions": obj.get("custom_instructions"),
            "model": obj.get("model"),
            "comments": [Comment.from_dict(_item) for _item in obj["comments"]] if obj.get("comments") is not None else None,
            "updated_at": obj.get("updated_at")
        })
        return _obj


