# coding: utf-8

"""
    OpenAI Connector server

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.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, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from openai_connector_v2.models.chat_history_item import ChatHistoryItem
from openai_connector_v2.models.file_payload import FilePayload
from openai_connector_v2.models.response_schema_payload import ResponseSchemaPayload
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class PromptBundle(BaseModel):
    """
    PromptBundle
    """ # noqa: E501
    model: Optional[StrictStr] = None
    system_prompt: StrictStr
    history: Optional[List[ChatHistoryItem]] = None
    user_prompt: StrictStr
    file: Optional[FilePayload] = None
    response_schema: Optional[ResponseSchemaPayload] = None
    skip_moderation: Optional[StrictBool] = False
    __properties: ClassVar[List[str]] = ["model", "system_prompt", "history", "user_prompt", "file", "response_schema", "skip_moderation"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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 json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of PromptBundle 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 history (list)
        _items = []
        if self.history:
            for _item_history in self.history:
                if _item_history:
                    _items.append(_item_history.to_dict())
            _dict['history'] = _items
        # override the default output from pydantic by calling `to_dict()` of file
        if self.file:
            _dict['file'] = self.file.to_dict()
        # override the default output from pydantic by calling `to_dict()` of response_schema
        if self.response_schema:
            _dict['response_schema'] = self.response_schema.to_dict()
        # 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 history (nullable) is None
        # and model_fields_set contains the field
        if self.history is None and "history" in self.model_fields_set:
            _dict['history'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "model": obj.get("model"),
            "system_prompt": obj.get("system_prompt"),
            "history": [ChatHistoryItem.from_dict(_item) for _item in obj["history"]] if obj.get("history") is not None else None,
            "user_prompt": obj.get("user_prompt"),
            "file": FilePayload.from_dict(obj["file"]) if obj.get("file") is not None else None,
            "response_schema": ResponseSchemaPayload.from_dict(obj["response_schema"]) if obj.get("response_schema") is not None else None,
            "skip_moderation": obj.get("skip_moderation") if obj.get("skip_moderation") is not None else False
        })
        return _obj


